如何从表中选择所有id,然后从另一个表中选择id为s的所有歌曲?
$query = "SELECT * FROM songs WHERE id = (SELECT songid FROM top10 order by id)'";
答案 0 :(得分:6)
您可以使用IN
(或EXISTS
):
select *
from songs
where id in (
select songid
from top10 )
根据您的评论,您实际上可能正在使用JOIN
(只是意识到如果top10表中有重复记录,这可能会返回重复结果):
select s.*
from songs s
join top10 t on s.id = t.songid
order by t.id