sql联表查询如何去掉重复记录

2025-04-01 20:01:25
推荐回答(2个)
回答1:

select table1.name,table2.*
from
table1,table2 where table1.userid=table2.userid and table2.id in
(select min(id) as id from table1,table2 where table1.userid=table2.userid)

回答2:

select * from table2 where id in(
select  min(id) as id from table2 group by userid)