I have a question regarding MySQL DISTINCT and GROUP BY.
SELECT * FROM test
id first_name last_name date
-- ---------- --------- ----
1 Tadej Lasic 2001-01-01
2 Luka Jerebic 2001-01-02
3 Pajo Makina 2001-01-03
4 Tadej Lasic 2001-01-04
5 Pajo Makina 2001-01-05
As you can see I have some identical first and last names. I would like to only display
them once and sort them by date. So it should display something like this:
id first_name last_name date
-- ---------- --------- ----
5 Pajo Makina 2001-01-05
4 Tadej Lasic 2001-01-04
2 Luka Jerebic 2001-01-02
Now, if I use the GROUP BY clause, which groups fields from the beginning to the end, I get
this:
SELECT * FROM test GROUP BY first_name ORDER BY date DESC
id first_name last_name date
-- ---------- --------- ----
3 Pajo Makina 2001-01-03
2 Luka Jerebic 2001-01-02
1 Tadej Lasic 2001-01-01
But that's not what I want. I would like to display distinct names, which where created the last
not the first.
I've tried it with DISTINCT but it only works/displays fields which have identical values (fist_name, last_name).
Can this be done and how? Any help would be appreciated.