I need 3 tables that are all relevant to the same thing.
For instance, 1 has user information, 1 has page information for that user and the other has page options for that user.
all connected through user_id
is is possible to do this.
SELECT *
FROM users
LEFT JOIN page_info ON users.id=page_info.user_id
RIGHT JOIN page_settings ON user.id=page_settings.user_id
WHERE users.id=$id
or will i be defeated to using 2 queries
Thanks
I think you misunderstand what a LEFT
and RIGHT
outer join do: read A Visual Explanation of SQL Joins .
In your case, with the users
table coming first (ie to the "left" of all others), I suspect you want both joins to be LEFT
outer joins? That is:
SELECT *
FROM users
LEFT JOIN page_info ON users.id = page_info.user_id
LEFT JOIN page_settings ON users.id = page_settings.user_id
WHERE users.id = $id
Yes, you can.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.