验证是否验证 Where 子句中的列


verify or not the column in where clause

我需要验证 2 列,但有时第二列为空然后我需要验证第二列,如果它不为空,否则它只会验证第一列

SELECT * 
FROM table 
WHERE column1 = $_GET['id'] 
and column2 IS NOT NULL = $_GET['id']

这是你想要的逻辑吗?

SELECT *
FROM table
WHERE column1 = $_GET['id'] and
      (column2 IS NULL or column2 = $_GET['id']);
SELECT IF(column1 IS NULL, column2, column1)
FROM table 
WHERE column1 = $_GET['id'] OR column2 = $_GET['id']