日期:2014-05-18  浏览次数:20502 次

去除重复的数据.
select     *   from
(
select*   from   a
union   all
select   *   from   b
)temp
group   by   id,name,age
having   count(*)=1
record
-----------------------
id               name           age
1 aa 22
1 aa 33
8 hh 44
8 oo 44
9 ii 44
9 ll 44
10 jj 44
我想得到这样的结果应该加什么条件呀?主要是要那个name,但不要重复的.

record
-------------
id               name          
1 aa
8 hh
8 oo
9 ii
9 ll
10 jj

先谢谢了!

------解决方案--------------------
select id,name from tablename where age in(select max(age) from tablename group by name)
------解决方案--------------------
max--放错位置了
select * from 表A as B
where age=(select max(age) from 表A where id =b.id and name=b.name)--保留大的