以下代码应该返回与另一个表中的参数匹配或根本不匹配 ID 的结果。
这是我的尝试,我不明白为什么它不起作用。它返回结果数的许多倍。
SELECT *
FROM table2, table1
WHERE table1.ID = table2.name
AND table1.value = 1
OR table1.ID != table2.name
如何解决这个问题
Looks like you need some parenthesis
FROM table2, table1 WHERE (table1.ID = table2.name AND table1.value = 1) OR table1.ID != table2.name
FROM table2, table1 WHERE table1.ID = table2.name AND (table1.value = 1 OR table1.ID != table2.name)
You can do two things:
Look to here for an explanation of them: http://www.w3resource.com/sql/joins/perform-a-full-outer-join.php
SELECT *
FROM table2, table1
WHERE table1.ID = table2.name(+)
AND table1.value = 1
An example up, there, untested but I think it'll work