Answer the question
In order to leave comments, you need to log in
How to pull out all related columns knowing the id of one?
There are related tables. Let's say books, genres and binder "genres of books". Books, of course, can have several genres. How to pull books that have genre "1", while capturing the rest of the genres in one request?
I came to such a decision, "works", but I think there is a more correct, correct solution.
SELECT
b.id, GROUP_CONCAT(g.id) as gid
FROM book b
LEFT JOIN books_genre bg ON bg.books_id = b.id
LEFT JOIN genre g ON g.id = bg.genre_id
GROUP BY b.id
HAVING (FIND_IN_SET(1,gid))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question