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个区别,谢谢

解决方案 »

  1.   

    当你table存在数据重复时(即id salary相同)两句就不会相同。
      

  2.   

    distinct作用是去掉SELECT出记录的重复项
      

  3.   

    select distinct t1.id ,distinct(t1.salary) from table t1,table t2 where t1.salary=t2.salary;
    你再试试,就是你想看到的效果了
      

  4.   

    应该学习最基本的SQL知识,DISTINCT的意思是如果一个表中有完全一样的数据多条,那么结果就只取一条。
    例如
    5 60
    5 60不加DISTINCT 结果会取出两条数据,
    如果加上DISTINCT 结果只会取一条数据。
      

  5.   

    如果表table 有主键约束,结果一样
    即使是 select distinct t1.id ,t1.salary from table t1,table t2  也是一样的
    但前者效率低
      

  6.   

    回malligator
    不是故意的 前面那个没有排序 但是出来的结果是按照升序排的。