If I want to grab data from two tables is it...
SELECT * FROM table1, table 2 WHERE id = $id ??
Grabbing data from two tables
Moderator: General Moderators
Or similiar to McGruff's example:
Code: Select all
select
tablea.*, tableb.*
from
tablea
inner join tableb on tablea.id = tableb.id
where
tablea.id = '$id'How would this work for grabbing all information when there is a 1:n relationship between the data?
The case I am thinking about is where there is an item table and a user table. Each item can have multiple users associated with it. The item table references the user table by ids. The user table has things like first name, last name, email, etc.
How do I grab all user's user data that is associated with a particular item?
I can do the join (like described earlier in this thread) to get one, but not all users...
Thanks!
mcp
The case I am thinking about is where there is an item table and a user table. Each item can have multiple users associated with it. The item table references the user table by ids. The user table has things like first name, last name, email, etc.
How do I grab all user's user data that is associated with a particular item?
I can do the join (like described earlier in this thread) to get one, but not all users...
Thanks!
mcp
This might be worth looking into:
http://jinxidoru.com/tutorials/union.html
http://jinxidoru.com/tutorials/union.html