从query where子句中的配置表中检索值

时间:2016-04-11 06:31:42

标签: sql sql-server

我需要构建一个从配置表中检索值的SQL Server 2012查询。代码如下所示:

Product
product_types product_description
001 Milk 
002 Butter
003 Oatmeal

Configuration_table

product_nr
001
003

查询:

SELECT *
FROM product
WHERE product.types in (select product_nr from configuration_table)

仅显示001和003。但是这个查询没有结果。如何纠正?

感谢您的回复!

1 个答案:

答案 0 :(得分:1)

您的查询似乎很好,但仍无法正常工作尝试修剪在where where条件

中使用的列
SELECT *
FROM product
WHERE TRIM(product.types) in (select TRIM(product_nr) from configuration_table)
相关问题