让我说我有
ID | Column 1 | Column 2
2 | NULL | "a"
3 | "b" | NULL
4 | "c" | "c"
我想写的是:
SELECT ID FROM table,AnotherTable
WHERE (Table.Column1 = AnotherTable.Column IF Table.Column1 IS NOT NULL
OR Table.Column2 = AnotherTable.Column IF Table.Column2 IS NOT NULL)
编辑:我也添加了案例IF Table.Column1 IS NOT NULL和Table.Column2 IS NOT NULL,然后选择Table.Column2 = AnotherTable.Column
最佳答案
您可以使用
原文链接:https://www.f2er.com/mysql/433438.htmlCOALESCE()
功能:
SELECT ID
FROM table JOIN AnotherTable
ON AnotherTable.Column = COALESCE(table.Column1,table.Column2)