天天看點

查詢表中重複記錄

聯表查詢、去除重複值、查找 表中 多餘 的重複記錄 、查找表中 沒有重複記錄的行

select * from table1

select * from table2

select a.*,b.* from table1 a, table2 b where a.id=b.e

-- 查詢表 1 列X有重複的值,則隻取一條

select min(id) as id,b,c from table1 group by b,c order by id asc

-- 1、查找表中 多餘的重複記錄 ,重複記錄是根據單個字段(peopleId)來判斷

select * from table1 where b in (select  b  from  table1  group  by  b  having  count(b) > 1)

-- 1、查找表中 沒有重複記錄的行

select * from table1 where b in (select  b  from  table1  group  by  b  having  count(b) = 1)

select a.*,b.id,b.e from table1 a inner join (select min(id) as id,e from table2 group by e) b on a.id=b.e

-- 查詢2表關聯的,而且不重複的記錄

select aa.*,bb.f from (select a.*,b.ids,b.e from table1 a inner join (select min(id) as ids,e from table2 group by e) b on a.id=b.e) aa inner join table2 bb on aa.ids=bb.id