我知道这个问题是一个血腥的初学者问的问题,但任何人都可以像看待这段代码那样善良:
SELECT w.word
FROM words
AS w
INNER JOIN words as w1 ON w.meaning=w1.meaning
AND w1.word='word1'
表格如下:
id meaning word
1 1 word1
2 1 word2
3 1 word3
4 2 word4
5 2 word5
6 3 word6
上面的代码给出了结果Violine,Fiedel和Geige ......但是我想要一直在搜索的单词不包含在结果中。我怎样才能做到这一点?
答案 0 :(得分:3)
你想要w1.word是Violine的所有结果,除了w.word本身是Violine的那个?
SELECT w.word
FROM words
AS w
INNER JOIN words as w1 ON w.meaning=w1.meaning
AND w1.word='Violine'
AND w.word <> 'Violine'
答案 1 :(得分:1)
只需在WHERE子句中过滤它:
SELECT w.word
FROM words
AS w
INNER JOIN words as w1 ON w.meaning=w1.meaning
AND w1.word = 'Violine'
AND w.word <> w1.word