Mysql DISTINCT not working if I add another column

后端 未结 2 797

mysql> select DISTINCT title, id from myadmins;

+------+------------+
| id   | title      |
+------+------------+
|    1 | admin      |
|    2 | stack      |
|           


        
2条回答
  •  醉梦人生
    2021-01-29 15:49

    You will get distinct (id, title) couples.

    The row with id=1 and title=admin is different from the row id=4 and title=admin.

    If you want only distinct titles from your table:

    select DISTINCT title from myadmins;
    
    +------------+
    | title      |
    +------------+
    | admin      |
    | stack      |
    | jeff       |
    +------------+
    

提交回复
热议问题