2013-08-01 27 views
-1

我想要做這樣的事情:SQL LIKE操作

SELECT * 
FROM 
    dictionary t1, 
    dictionary t2 
WHERE t1.category <> t2.category 
    AND t1.tag <> t2.tag 
    AND t1.word LIKE '% t2.word %'; 

如何編寫SQL的'% t2.word %'部分得到正確的結果?

回答

1
select * 
    from dictionary t1, 
     dictionary t2 -- <- Is there an intentional Cartesian Join? 
    where t1.category <> t2.category and 
     t1.tag <> t2.tag and 
     t1.word like '% ' || t2.word || ' %'; -- <- check spaces! 
+0

非常感謝,它的工作原理。 – yetAnotherSE

0

您需要使用該列。

select * 
from dictionary t1, dictionary t2 
where t1.category<>t2.category and t1.tag<>t2.tag and t1.word like '% ' + t2.word + ' %'; 
0
select * 
from dictionary t1, dictionary t2 
where t1.category<>t2.category and t1.tag<>t2.tag and t1.word like '%'+ t2.word +'%'; 
+0

提示錯誤:運營商不存在:未知+文字 SQL狀態:42883 提示:無操作比賽給定的名稱和參數類型。您可能需要添加顯式類型轉換。 – yetAnotherSE

+0

是的,如果你說Oracle我會給你||的回答! – LoztInSpace

+0

我不使用Oracle,我使用postgresql。謝謝你的回答。 – yetAnotherSE

0

這是你在找什麼:

select * 
from dictionary t1, dictionary t2 
where t1.category<>t2.category and t1.tag<>t2.tag and t1.word like '% ' + t2.word + ' %';