Mindzai
02-05-2009, 07:29 AM
I'm having a problem with some SQL. I have a working query which selects the most recent version of each webpage:
SELECT Version.webpage_id, Version.main_text, Version.created, ids.id
FROM cms_versions Version
INNER JOIN (SELECT MAX(id) AS id FROM cms_versions GROUP BY webpage_id) ids ON Version.id = ids.id
However what I need this to do, is select the second most recent version.
Any ideas on how I can achieve this?
Thanks in advance :)
SELECT Version.webpage_id, Version.main_text, Version.created, ids.id
FROM cms_versions Version
INNER JOIN (SELECT MAX(id) AS id FROM cms_versions GROUP BY webpage_id) ids ON Version.id = ids.id
However what I need this to do, is select the second most recent version.
Any ideas on how I can achieve this?
Thanks in advance :)