MYSQL Order before group and then Order again
Posted on 2013-01-24
I have a table with the following fields.
Basically, the id is uniue to each row, but the unique field may be the same as other rows.
What happens is when someone updates information in a form, rather than updating the existing row, it adds a new row which shared the same uniq field value as the original. Each time the user edits the row it loads in the most recently updated row. This allows us to keep a history or previous versions.
What I want to do is retrieve a list of items in the table, sort them by modified_date(desc), group by uniq, and then finally sort the result by name. The final array of results should list the latest modified_date sorted by name.
Just wondering how I would go about doing this? Currently my query is...
SELECT * FROM table GROUP BY unique ORDER BY "modified_date DESC, name ASC"
But obviously the final results are listed by modified date.