思路:
- 连接三个表
- 求出关注的人喜欢的音乐的id
- 同时排除用户user_id = 1喜欢的音乐的id
- 最后对music_id进行去重及对music.id进行排序
完整代码:
select distinct t3.music_name
from follow t1, music_likes t2, music t3
where t1.follower_id = t2.user_id
and t2.music_id = t3.id
and t1.user_id =1
and t2.music_id not in (select music_id
from music_likes
where user_id =1)
order by t3.id