Help with SQL query
Posted on 2012-03-25
I'm having some problems with a query I'm trying to put together.
I have the following tables.
What I want to do is list all folders where the user has an entry in the PERMISSIONS table for.
So there are two conditions
1) List folders where the parent_id = a supplied ID, and where the user has an entry in the PERMISSIONS table
2) List folders where the user isn't the creator of the folder, but is in the PERMISSIONS folder
This is what I've got so far...
SELECT f.id,f.name,f.trash,f.parent_id,f.create_user_id,f.create_date FROM folders AS f, folder_permissions AS p WHERE f.trash = 0 AND p.user_id = '".$user_id."' AND p.folder_id = f.id AND (f.parent_id = '".$parent_id."' OR p.user_id != f.create_user_id) GROUP BY f.id ORDER BY f.name ASC
Can anyone point out where I might be going wrong?