table表有id、name两个字段:
有数据:
1、a;
2、b;
3、c;
4,c;
5、b
select distinct name from table; ——>name a b c
select distinct name, id from table ——>id name 1 a 2 b 3 c 4 c 5 b(id与name都相同的才会被排除)
select id, distinct name from table ——>报错,distinct必须放在开头
select *, count(distinct name) from table group by name ——>1 a 1 2 b 1 3 c 1
有数据:
1、a;
2、b;
3、c;
4,c;
5、b
select distinct name from table; ——>name a b c
select distinct name, id from table ——>id name 1 a 2 b 3 c 4 c 5 b(id与name都相同的才会被排除)
select id, distinct name from table ——>报错,distinct必须放在开头
select *, count(distinct name) from table group by name ——>1 a 1 2 b 1 3 c 1
group by 必须放在 order by 和 limit之前,不然会报错
原文摘自:http://cache.baiducontent.com/c?m=9d78d513d99e01fc09b3c3690d67813d5812db3f6d91c7150ec3e54e84105c563667f4cb21351174c4b37d7070ae5d1baaae3928714562a09abb955798fed73f2fff76682042db1453c419d89a1b7adc76cd0fa3e84eb3edac678efd9282850f179d4e057883f096580409ca6ced1436e4a39c4a174810cdb7763aa1&p=882a9545d68c1fe604aa8e2d0214c6&newp=8f759a45d6c35afd1ab0c7710f41c4231610db2151d0d00e2d96ce&user=baidu&fm=sc&query=oracle+distinct+%D4%F5%C3%B4%D3%C3&qid=&p1=3