Answer the question
In order to leave comments, you need to log in
How to reduce three queries into one?
I have 3 tables:
music (основная)
--
id, path, duration... и т.д.
genre (тут идут названия жанров и их id)
---
genre_id
genre_title
xref_music_genre (а тут отношения id песен из основной таблицы к названию жанра из второй таблицы)
---
music_id
genre_id
SELECT music_id FROM xref_music_genre WHERE genre_title = 'trance'
Answer the question
In order to leave comments, you need to log in
select m.* from music m, genre g, xref_music_genre mg
where m.id = mg.music_id
and g.genre_id = mg.genre_id
and g.genre_title = 'rock'
SELECT m.*, GROUP_CONCAT(g.genre_title ORDER BY g.genre_title ASC SEPARATOR'; ') as genre_titles
FROM music m
INNER JOIN xref_music_genre mg ON mg.music_id = m.id
INNER JOIN genre g ON g.genre_id = mg.genre_id
GROUP BY m.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question