MySQL SELECT DISTINCT multiple columns

后端 未结 6 1392
误落风尘
误落风尘 2020-11-27 05:28

Let\'s say I have columns a, b c, d in a table in a MySQL database. What I\'m trying to do is to select the distinct values of ALL of these 4 columns in my tabl

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 05:46

    Both your queries are correct and should give you the right answer.

    I would suggest the following query to troubleshoot your problem.

    SELECT DISTINCT a,b,c,d,count(*) Count FROM my_table GROUP BY a,b,c,d
    order by count(*) desc
    

    That is add count(*) field. This will give you idea how many rows were eliminated using the group command.

提交回复
热议问题