SQL/mysql - Select distinct/UNIQUE but return all columns?

前端 未结 18 938
忘掉有多难
忘掉有多难 2020-11-22 12:08
SELECT DISTINCT field1, field2, field3, ......   FROM table

I am trying to accomplish the following sql statement but I want it to return all colum

18条回答
  •  逝去的感伤
    2020-11-22 12:25

    Add GROUP BY to field you want to check for duplicates your query may look like

    SELECT field1, field2, field3, ......   FROM table GROUP BY field1
    

    field1 will be checked to exclude duplicate records

    or you may query like

    SELECT *  FROM table GROUP BY field1
    

    duplicate records of field1 are excluded from SELECT

提交回复
热议问题