Reason for - ORDER BY items must appear in the select list if SELECT DISTINCT is specified

前端 未结 2 553
攒了一身酷
攒了一身酷 2021-01-05 20:28

I know that the query below causes the error - ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

SELECT DISTINCT city
FROM HR.Em         


        
2条回答
  •  旧巷少年郎
    2021-01-05 21:30

    try this: 
    select city 
        from (
        SELECT city, min(birthdate) as birthdate
        FROM HR.Employees
        WHERE country = N'USA' AND region = N'WA'
        group by city
              ) as t
        order by birthdate
    

提交回复
热议问题