2013-06-18 78 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這個看起來不錯!我會盡力讓你知道 –