So far I'm doing it this way:
SELECT * FROM table_name WHERE column in(var1,var2,var3) or column is NULL
I have issues with repeating column name two times here since in() can't take null as an argument, it returns also no error, just 0 columns. (Maybe some magic variables that can refer last 开发者_如何学运维called column ?)
This:
'column'
is a string literal, not a column name. So this:
'column' in(var1,var2,var3) or 'column' is NULL
won't match anything unless var1, var2, or var3 happen to be the string 'column'. Try dropping the quotes on the column name:
SELECT * FROM table_name WHERE column in (var1, var2, var3) or column is NULL
Another option without repeating column name:
SELECT * FROM table_name WHERE coalesce(column,'NULL') in (var1,var2,var3,'NULL')
You could do a union select:
SELECT
*
FROM
`table_name`
WHERE
`column` IN (var1, var2, var3)
UNION
SELECT
*
FROM
`table_name`
WHERE
`column` IS NULL
加载中,请稍侯......
精彩评论