Consider the following query:
SELECT domain, done FROM tasks WHERE 1 GROUP BY domain
Obviously I can get it to return the max value of “done” with MAX(done), but how do i get it to return that whole row?
In the situation I’m in, I have a table with the following rows:
domain = somedomain.com, done = 12:27:39, somecolumn = pink
domain = somedomain.com, done = 13:27:39, somecolumn = blue
domain = somedomain.com, done = 14:27:39, somecolumn = orange
domain = anotherdomain.com, done = 07:27:39, somecolumn = orange
domain = anotherdomain.com, done = 09:27:39, somecolumn = pie
Using the query above, it returns the following 2 rows:
domain = somedomain.com, done = 13:27:39, somecolumn = blue
domain = anotherdomain.com, done = 09:27:39, somecolumn = pie
I need to return these 2 rows:
domain = somedomain.com, done = 14:27:39, somecolumn = blue
domain = anotherdomain.com, done = 09:27:39, somecolumn = pie
Appreciate the help :).
Easiest one:
For more elaborate queries, left joins or subqueries may be needed, but this one is pretty straight forward.
For the heck of it, if you indeed need other data:
(1) NOT EXISTS:
(2) LEFT JOIN
(3) ROWNUMBER() like:
Which one will give you better performance hugely depends on the dataset, so I’d just test those.