ripcurlksm Posted January 2, 2007 Share Posted January 2, 2007 I have three tables set up: user, reports & permissions. I need some help in executing a SQL query and I am having a tough time getting the right results.[B]Summary:[/B]I have a login setup so that a user can login and view reports that they have permission to see. I need the SQL statement to get the user's id, then select all of the rows in the "permissions" table where there id is present AND get the "report id" associated inside that table, THEN select all of the rows in the "report" table that have the "report id" from the previous query.[B]Here is my database schema:[/B][CODE]user==================id | username ==================1 | bob2 | johnreports===============================id | title | company ===============================1 | Green | Crayola2 | Red | Bic3 | Blue | Papermatepermissions===========================user_id | report_id ===========================1 | 11 | 22 | 12 | 3**So Bob would get "Green" and "Red" and John would get "Red" and "Blue"**[/CODE][B]Here is my incomplete SQL query. I still need to reference the permissions table and I am really lost on this one.[/B][color=red]SELECT reports.* FROM user, report WHERE user.id = reports.id;[/color]Can anyone suggest a correct query? Quote Link to comment https://forums.phpfreaks.com/topic/32502-query-multiple-tables-ii/ Share on other sites More sharing options...
dbo Posted January 2, 2007 Share Posted January 2, 2007 $userid = 1; //bob$query = "SELECT reports.title FROM report, permissions WHERE permissions.userid = $userid";? Quote Link to comment https://forums.phpfreaks.com/topic/32502-query-multiple-tables-ii/#findComment-151217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.