select distinct t1.id ,t1.salary from table t1,table t2 where t1.salary=t2.salary;select id,salary from table order by salary这2个有什么区别吗???
我今天试验了一下,数据库数据如下:
id salary
1 100
2 200
3 300
4 200
5 50
6 50
但是我查出来的数据是一样的阿??? 所以请高手指教一下这2个区别,谢谢
我今天试验了一下,数据库数据如下:
id salary
1 100
2 200
3 300
4 200
5 50
6 50
但是我查出来的数据是一样的阿??? 所以请高手指教一下这2个区别,谢谢
你再试试,就是你想看到的效果了
例如
5 60
5 60不加DISTINCT 结果会取出两条数据,
如果加上DISTINCT 结果只会取一条数据。
即使是 select distinct t1.id ,t1.salary from table t1,table t2 也是一样的
但前者效率低
不是故意的 前面那个没有排序 但是出来的结果是按照升序排的。