when dealing with NULL
, you cannot use =
or <>
since the values are unknown but instead use IS NULL
or IS NOT NULL
,
WHERE COLLABORATORS.userid = 23 and FOLDER.parent IS NULL
Question
I got this query that works perfectly:
SELECT FOLDER.folderid, FOLDER.foldername
FROM FOLDER
INNER JOIN COLLABORATORS ON COLLABORATORS.folderid = FOLDER.folderid
WHERE COLLABORATORS.userid = 23
But when I added this on the where clause: "and FOLDER.parent = NULL" it doesnt work. The complete query is:
SELECT FOLDER.folderid, FOLDER.foldername
FROM FOLDER
INNER JOIN COLLABORATORS ON COLLABORATORS.folderid = FOLDER.folderid
WHERE COLLABORATORS.userid = 23 and FOLDER.parent = NULL
Does anyone know whats going on? Thanks
Solution
when dealing with NULL
, you cannot use =
or <>
since the values are unknown but instead use IS NULL
or IS NOT NULL
,
WHERE COLLABORATORS.userid = 23 and FOLDER.parent IS NULL
OTHER TIPS
Change this query
WHERE FOLDER.parent = NULL
to
WHERE FOLDER.parent IS NULL
Because the result of any arithmetic comparison with NULL is also NULL, you cannot obtain any meaningful results from such comparisons.
For fetching Null Records from a table, it is required to use where [column] is null. the condition specified in your query FOLDER.parent = NULL, will look for 'NULL' String(word) in the required column. you can check this by inserting 'NULL' string(word) in the above column.