Q: Getting last dated rows from multiple IDs I'm currently making the backend of an application updater and i use my server to keep track of all files and revisions.
Currently i have two tables in my database:
dev_version_control_files
Columns: FileID, FileName

dev_version_control_versions
Columns: VersionID, FileID, Version, DateReleased, FileLocation

The files table keeps one record for every file that's under version control. The version table keeps one record for every version of each file along with the date its released, its version number and location.
Now what i want is to get the last record (update) of every file in the files table. This should be decided by the date field, that holds a unix timestamp from when it was released.
I don't want to go through every row in the version table every time an update request is made, so would it be possible to do this in one query? 

A: I'm not a SQL expert, but would this work?
SELECT f.*, v.DateReleased
FROM dev_version_control_files f
INNER JOIN (
  SELECT FileId, MAX(DateReleased) AS DateReleased
  FROM dev_version_control_versions
  GROUP BY 1) v ON f.FileID = v.FileID

I'll test this out on a sample table now to see (I think some syntax may be off), but the idea is to pull the max dates from the versions table and group them by ID, then join to the files  table on ID. Is this what you were already doing?

A: You need to get first the maximum DateReleased for each FileID the join them later with dev_version_control_files and dev_version_control_versions
SELECT a.*, b.Version, DateReleased
FROM    dev_version_control_files a 
            INNER JOIN dev_version_control_versions b
                on a.FileID = b.FileID
            INNER JOIN
            (
                SELECT FileID, MAX(DateReleased) MaxDate
                FROM dev_version_control_versions
                GROUP BY FileID
            ) c ON b.FileID = c.FileID AND
                   b.DateReleased = c.MaxDate


A: Assuming you have at least one version record in the second table:
SELECT FileID, FileName, MAX(DateReleased)
FROM dev_version_control_files
INNER JOIN dev_version_control_versions ON FileID
GROUP BY FileID, FileName

This is not exact SQL, it's a rough idea of how I would go about this.
