mysql multiple where and inner join query combination
Posted
by bandhunt
on Stack Overflow
See other posts from Stack Overflow
or by bandhunt
Published on 2010-05-11T22:17:47Z
Indexed on
2010/05/11
22:24 UTC
Read the original article
Hit count: 219
I'm a little lost as how to run two mysql queries as one(return one result set to be sorted etc).
I understand how to do multiple JOINS but need to combine the below which is more than just a multiple join - it would include a multiple where etc.
1st query
sql = "SELECT s.id, s.song_name
FROM `songs` as s
INNER JOIN `artists` as a ON s.artist_id = a.id
WHERE ((`a`.id = #{search}))"
2nd query
sql = "SELECT s.id, s.song_name
FROM `songs` as s
INNER JOIN `similarments` as si ON s.artist_id = si.artist_id
WHERE ((`si`.similar_id = #{search}))"
And then run both queries at once so I can ORDER them etc. Or combine them as one big query (maybe put an OR somewhere)?
Thanks!
© Stack Overflow or respective owner