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

前端 未结 5 689
梦谈多话
梦谈多话 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:06

    If your DBMS doesn't support distinct with multiple columns like this:

    select distinct(col1, col2) from table
    

    Multi select in general can be executed safely as follows:

    select distinct * from (select col1, col2 from table ) as x
    

    As this can work on most of the DBMS and this is expected to be faster than group by solution as you are avoiding the grouping functionality.

提交回复
热议问题