我需要验证2列,但有时第二列是空的 然后我需要验证第二列,如果它不是空的,否则它将只验证第一列
SELECT *
FROM table
WHERE column1 = $_GET['id']
and column2 IS NOT NULL = $_GET['id']
答案 0 :(得分:3)
这是你想要的逻辑吗?
SELECT *
FROM table
WHERE column1 = $_GET['id'] and
(column2 IS NULL or column2 = $_GET['id']);
答案 1 :(得分:0)
SELECT IF(column1 IS NULL, column2, column1)
FROM table
WHERE column1 = $_GET['id'] OR column2 = $_GET['id']