有点复杂的问题,但是,基本上我有很多表word_relationships:
word_relationships
+-----+--------+--------+ | ID | WORD_A | WORD_B | +-----+--------+--------+ | 1 | 784 | 893 | +-----+--------+--------+ | 2 | 930 | 839 | +-----+--------+--------+ | 3 | 093 | 647 | +-----+--------+--------+
它是word a和word b关系的列表。我需要查询以查找word_a和word_b之间的关系是否存在。如果单词可以是单词A或单词b,那么正确的语法是什么?
word a
word b
在我的脑海里
w1 = 784 w2 = 893 "SELECT ID FROM word_relationships WHERE WORD_A = w1 OR WORD_B = w1 AND WORD_A = w2 OR WORD_B = w2";
这似乎不起作用,因为我得到了任何一场比赛的结果。有人熟悉这种情况并知道正确的语法吗?
提前致谢。
这应该工作:
SELECT id FROM word_relationships WHERE (Word_A = w1 AND Word_B = w2) OR (Word_A = w2 AND Word_B = w1)