I have a table FOLDERS,everytime a folder is added through a php page it gets inserted into FOLDERS.
each folder has these fields: id,userid,foldername
I simplified the table to make my question easier to grasp.
ID UID FOLDERNAME
1 – 1 – Books
2 – 1 – Receipts
3 – NULL – Books
4 – NULL – Receipts
5 – NULL – Home
6 – 2 – Receipts
I would like to know how to get the fifth row as a result.
The condition would be: The fact that row 5 doesnt have any UID (its empty) and is doesn’t exist with a uid. When I use:
$sql="SELECT * FROM folders WHERE userid=''";
this returns ALL the rows with an empty userid. I only want 5 as a result because UID=1 already has his folder Receipts and Books set.
any suggestions would help I ve been struggling with this for a couple of hours now. Thank you
Combine a condition
userid IS NULLfor null userid rows with aNOT IN()subquery which returns all the distinct folder names which do have auseridin other rows.