2013-06-18 79 views
6

我该如何完成这项工作?SQL与子查询相似

select * from item where item_name like '%' || (select equipment_type from equipment_type group by equipment_type) || '%' 

内部子查询返回像'的'测试“另一个”字符串列表,我想选择的项目表,其中ITEM_NAME类似于子查询返回值的所有项目。我需要有通配符。

是否有替代方案,我可以使用通配符,但使用IN sql命令呢?

+0

别你有ID做这个? – TechBytes

+0

@TechBytes你是什么意思? –

+0

@TechBytes我明确指出,我有一个我想比较item_name的字符串列表。 –

回答

11

您可以使用INNER JOIN

SELECT I.* 
FROM item I 
INNER JOIN (SELECT equipment_type 
      FROM equipment_type 
      GROUP BY equipment_type) E 
    ON I.item_name LIKE '%' || E.equipment_type || '%' 
+0

ahhh不错,我会试试这个,让你知道尽快。 ty –

3

如果你不想担心重复并不在乎哪一个相匹配,然后切换到使用exists

select i.* 
from item i 
where exists (select 1 
       from equipment_type 
       where i.item_name like '%'||equipment_type||'%' 
      ) 
+0

oohhhh这个看起来不错!我会尽力让你知道 –