Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top