How do I (or can I) SELECT DISTINCT on multiple columns?

前端 未结 5 673
梦谈多话
梦谈多话 2020-11-21 23:53

I need to retrieve all rows from a table where 2 columns combined are all different. So I want all the sales that do not have any other sales that happened on the same day f

5条回答
  •  离开以前
    2020-11-22 00:19

    I want to select the distinct values from one column 'GrondOfLucht' but they should be sorted in the order as given in the column 'sortering'. I cannot get the distinct values of just one column using

    Select distinct GrondOfLucht,sortering
    from CorWijzeVanAanleg
    order by sortering
    

    It will also give the column 'sortering' and because 'GrondOfLucht' AND 'sortering' is not unique, the result will be ALL rows.

    use the GROUP to select the records of 'GrondOfLucht' in the order given by 'sortering

    SELECT        GrondOfLucht
    FROM            dbo.CorWijzeVanAanleg
    GROUP BY GrondOfLucht, sortering
    ORDER BY MIN(sortering)
    

提交回复
热议问题