您的位置:首页 > 其它

distinct 去重复查询——两个表join 连接,去掉重复的数据

2014-04-21 17:07 309 查看
------distinct 去重复查询

select * from accounts acc join (select distinct accid from roles) r on r.accid=acc.ID

-----不需要distinct select * from (select MAX(ID)roleid,accid from roles group by accid) rr join (select * from accounts) acc on acc.ID=rr.accid

--------解释一下不用distinct 去重复查询语句

Select * from (Select max(不重复的字段就行) as roleid,要去重复字段名 From 数据表 Where 条件 Group by 要去重复字段名) as A join 数据库表 on 条件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐