Mysql select distinct

前端 未结 5 1894
孤街浪徒
孤街浪徒 2020-12-01 06:25

I am trying to select of the duplicate rows in mysql table it\'s working fine for me but the problem is that it is not letting me select all the fields in that query , just

5条回答
  •  臣服心动
    2020-12-01 06:41

    DISTINCT is not a function that applies only to some columns. It's a query modifier that applies to all columns in the select-list.

    That is, DISTINCT reduces rows only if all columns are identical to the columns of another row.

    DISTINCT must follow immediately after SELECT (along with other query modifiers, like SQL_CALC_FOUND_ROWS). Then following the query modifiers, you can list columns.

    • RIGHT: SELECT DISTINCT foo, ticket_id FROM table...

      Output a row for each distinct pairing of values across ticket_id and foo.

    • WRONG: SELECT foo, DISTINCT ticket_id FROM table...

      If there are three distinct values of ticket_id, would this return only three rows? What if there are six distinct values of foo? Which three values of the six possible values of foo should be output?
      It's ambiguous as written.

提交回复
热议问题