联表查询、去除重复值、查找表中多余的重复记录、查找表中没有重复记录的行
2010-10-20 23:04
676 查看
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
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
相关文章推荐
- Oracle 删除重复数据只留一条 查询及删除重复记录的SQL语句 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 wher
- Oracle 删除重复数据只留一条 查询及删除重复记录的SQL语句 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 wher
- 查找表中多余的重复记录(多个字段)
- mysql给列的属性赋值,修改列属性,删除记录,删除所有记录,查询表的记录,去除重复的,总和查询,条件查询,模糊查询,关联查询,范围查询
- 解析mysql中:单表distinct、多表group by查询去除重复记录
- 解析mysql中:单表distinct、多表group by查询去除重复记录
- sqlite查询数据库去除重复记录
- sql语句去除重复记录(多表连接的查询)
- mysql having,group by查询去除重复记录
- mysql中:单表distinct、多表group by查询去除重复记录
- 查询两张关联表去除重复记录
- 查找表中多余的重复记录(多个字段)
- MYSQL 查询多余重复的记录
- 查找sql表中多余的重复记录
- ORACLE 去除多余的重复记录语句
- SQL查询重复记录,去除重复记录
- oracle查找重复记录,去除重复记录
- mysql查询时去除重复数据以及 FOUND_ROWS 统计记录函数
- sql 单表distinct/多表group by查询去除重复记录
- 查询数据表,去除符合某些条件的记录,没有自动增长列(not exists)