can you help me to get just one newest row from each category from DB?

DB Example:

Table name Colors:

id category timestamp
1 yellow 14/2/2014

2 blue 13/2/2014

3 red 14/2/2014

4 yellow 13/2/2014

5 blue 11/2/2014

How i can in sql query select from table just newest row from each category?

Expected result:

1 yellow 14/2/2014

2 blue 13/2/2014

3 red 14/2/2014

Thanks for any response

有帮助吗?

解决方案

SELECT id, category, MAX(timestamp) FROM TABLE GROUP BY CATEGORY

Anyway i don't even know if your timestamp will work in this case, you need to format your timestamp from DD/MM/YYYY to YYYY/MM/DD for this to work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top