Return all columns with distinct on multiple columns in SQL table

前端 未结 2 1426
梦毁少年i
梦毁少年i 2021-01-29 16:03

I have 5 columns in sql table and I need all the 5 columns as out put but with distinct operation on three columns

Need to return all the columns with distinct operation

相关标签:
2条回答
  • 2021-01-29 16:27

    You can use a groupby for the three columns you want 'distinct'.

    0 讨论(0)
  • 2021-01-29 16:42

    Can group by 3 but must use some type of aggregate function like min or max on the other two

    select col1, col2, col3, max(col4), min(col5) 
    from tbl 
    group by col1, col2, col3
    
    0 讨论(0)
提交回复
热议问题