I have a question regarding pulling data from different tables in MYSQL
. I'm sorry if this question has already been answered elsewhere, but I just can't seem to make sense of it.
I want to pull out the categories that are bound to the user's chosen newspapers.
I've got a table that tracks the user's chosen newspapers with user_id and newspaper_id . A table with the newspapers and another table with the categories . And at last a table which has both the newspaper_id and the category_id .
Is this possible to do with a single query? I'm really no good with sub select queries. Thanks in advance!
Joining is probably the way to go:
SELECT c.*
FROM categories c
JOIN newspaper_categories nc ON c.category_id = nc.categroy_id
JOIN newspaper_users nu ON nu.newspaper_id = nc.newspaper_id
WHERE nu.user_id = <some id>
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.