select
music_name
from music m
join
(select
distinct music_id
from music_likes
where user_id in (
select
follower_id
from follow
where user_id = 1
) and music_id not in(
select
music_id
from music_likes
where user_id =1
)) a
on a.music_id = m.id
order by m.id
查询里有distinct,为了避免出现id不同但是名字相同的情况,order by 后必须要接查询字段。所以distinct后置,放到where后的嵌套查询中。

京公网安备 11010502036488号