SheppardDigital
asked on
Help with SQL query
I'm having some problems with a query I'm trying to put together.
I have the following tables.
FOLDERS
id
name
trash
parent_id
create_user_id
PERMISSION
id
user_id
folder_id
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.pare nt_id,f.cr eate_user_ id,f.creat e_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?
I have the following tables.
FOLDERS
id
name
trash
parent_id
create_user_id
PERMISSION
id
user_id
folder_id
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.pare
Can anyone point out where I might be going wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER