SQL DISTINCT [替代使用]

时间:2010-12-24 13:29:18

标签: sql database oracle distinct

我对Oracle有一个简单的查询。

SELECT DISTINCT City, Name, Surname FROM Persons

对于没有DISTINCT的同一查询,是否有任何替代sql查询?

3 个答案:

答案 0 :(得分:2)

查看this article

示例为;

select City
from (
  select City,
         row_number() over 
           (partition by City
            order by City) rownumber
    from Persons
         ) t
   where rownumber = 1

答案 1 :(得分:1)

SELECT City, Name, Surname FROM Persons
UNION
SELECT City, Name, Surname FROM Persons

答案 2 :(得分:0)

SELECT First(City), First(Name), First(Surname)
FROM Persons
GROUP BY City, Name, Surname