Little help needed with sql query

Hello y'all..

In this query I have two tables, files and file_revisions. I want to select the file record, and join it to the latest file_revisions record for that file (joins using file_id field). For files that don't have a corresponding file_revisions record, I just want to get the file information.

Here is what I've came up with:
SELECT files.*, file_revisions.* FROM files
LEFT JOIN file_revisions
ON (file_revisions.file_id = files.file_id)
GROUP BY files.file_id, file_revisions.file_id
ORDER BY file_revisions.rev_date DESC

I am getting all the files, and the revision information.. but if there are is more than 1 file_revisions record, I seem to be getting the first one in the table (not the most recent).

Thanks for your time
Regards :wave:
[833 byte] By [HairyMonkeyMan] at [2007-11-19 19:50:59]
# 1 Re: Little help needed with sql query
And you want the most recent revision? right? If that is the case add a WHERE clause with this - WHERE file_revisions.revision_number = (SELECT MAX(revision_number) from file_revisions WHERE <give aliases to tables and put file_revisions_alias_A.revision_id = file_revisions_alias_B.revision_id>. Here revision_id = unique identifier for a record in file_revisions... Hope this helps. Regards.
exterminator at 2007-11-9 13:43:21 >