Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where clause based on conditions

Tags:

sql

I have a query where I match a column. The value to be matched may be null or not null (some value exists). The problem arises when the matching takes place. In case value is present the matching like

table.column = somevalue

works fine, but in case the value is null, then the matching needs to be done as

table.column is null

Is there some way that I can choose the condition being used in the WHERE clause based on the value?

Thanks in advance

like image 420
Rohan Avatar asked Feb 24 '23 20:02

Rohan


1 Answers

What about ORing your WHERE clause?

SELECT
*
FROM table
WHERE ((table.column = 123) AND table.column IS NOT NULL))
OR    (table.column IS NULL)
like image 143
plang Avatar answered Feb 26 '23 10:02

plang