mysql> select DISTINCT title, id from myadmins;
+------+------------+
| id | title |
+------+------------+
| 1 | admin |
| 2 | stack |
|
DISTINCT
applies to the entire row of data. Since the ID
is different on each row, then you will end up with duplicate titles.
If you need the ID
, then you could use an aggregate to get the MAX(ID)
:
select max(id) id,
title
from yourtable
group by title
order by id
See SQL Fiddle with Demo
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 |
+------------+