0

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

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

2 回答 2

3

这是你想要的逻辑吗?

SELECT *
FROM table
WHERE column1 = $_GET['id'] and
      (column2 IS NULL or column2 = $_GET['id']);
于 2013-09-13T19:15:30.183 回答
0
SELECT IF(column1 IS NULL, column2, column1)
FROM table 
WHERE column1 = $_GET['id'] OR column2 = $_GET['id']
于 2013-09-13T19:16:48.837 回答