Fury Fury - 4 months ago 7
SQL Question

MySQL display rows where value IS NULL or IN(2, 3)

I am trying to get enquiries that their teams are in 15, 9, 25, 26, 23, 18, 12 and null. The problems is the query doesn't retrieves the NULL records.

I have tried to use OR

team IS NULL
the query gives me all other statuses.

SELECT e.*,
FROM enquiries e
WHERE e.timestamp BETWEEN '1293840000' AND '1469055599'
AND e.status IN(1) AND e.team IN(15, 9, 25, 26, 23, 18, 12, NULL)
ORDER BY e.timestamp ASC


Any help please

Answer

Place OR condition in brackets

SELECT e.*,
FROM enquiries e
WHERE e.timestamp BETWEEN '1293840000' AND '1469055599'
AND e.status IN(1) AND ( e.team IN (15, 9, 25, 26, 23, 18, 12) OR e.team IS NULL)
ORDER BY e.timestamp ASC
Comments