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

有帮助吗?

解决方案

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

其他提示

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.

MySQL Manual

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top