Ok i got this table
+-----+-----------------------------+-------------+-------------+----------+---------+
| id | title | created | updated | category | content |
+-----+-----------------------------+---------------------+---------------------+----+
| 423 | What If I Get Sick and Die? | 2008-12-30 | 2009-03-11 | angst | NULL |
| 524 | Uncle Karl and the Gasoline | 2009-02-28 | NULL | humor | NULL |
| 537 | Be Nice to Everybody | 2009-03-02 | NULL | advice | NULL |
| 573 | Hello Statue | 2009-03-17 | NULL | humor | NULL |
| 598 | The Size of Our Galaxy | 2009-04-03 | NULL | science | NULL |
+-----+-----------------------------+---------------------+---------------------+----+
I try to get unique row for each category, so i query fo something like:
SELECT id,title,category FROM `entries` group by category
And the result is :
+-----+-----------------------------+----------+
| id | title | category |
+-----+-----------------------------+----------+
| 537 | Be Nice to Everybody | advice |
| 423 | What If I Get Sick and Die? | angst |
| 524 | Uncle Karl and the Gasoline | humor |
| 598 | The Size of Our Galaxy | science |
+-----+-----------------------------+----------+
The result looks fine, but how can i get row with category = humor and id = 573 instead?
If i query something like:
SELECT id,title,category, max(id) FROM `entries` group by category
I got result like this:
+-----+-----------------------------+----------+---------+
| id | title | category | max(id) |
+-----+-----------------------------+----------+---------+
| 537 | Be Nice to Everybody | advice | 537 |
| 423 | What If I Get Sick and Die? | angst | 423 |
| 524 | Uncle Karl and the Gasoline | humor | 573 |
| 598 | The Size of Our Galaxy | science | 598 |
+-----+-----------------------------+----------+---------+
Obviously thats not what i want, any help would be appreciated
And i want to know how exactly mysql collapse row for each group? Did mysql simply take first row for each group?
and a query with
GROUP BY
to get maximum id for every category (I guess you do want the row with maximum id for every category, don't you?)and a query to get maximum id for every category
and a correlated subquery
and a correlated subquery
I think this is what you want. I haven't tested it though.