On May 11, 2007, at 11:38 AM, Chris Perkins wrote:
The second is "Incorrect syntax near the keyword 'ON'" for:
SELECT select_2.ver AS select_2_ver, select_2.id AS select_2_id
FROM (SELECT [T].id AS id, [T].ver AS ver
FROM [T] JOIN ((SELECT [T].id AS mvid, max([T].ver) AS maxver
FROM [T] GROUP BY [T].id)) ON mvid = [T].id AND [T].ver = maxver) AS
select_2 ORDER BY select_2.id
the problem with that one is that you are joining to a select without
an alias name. set maxvers = maxvers.alias('foo') and see how that
works. you can also try rewriting that query using just the onclause
of the join without the JOIN keyword.
as always, the best way to do these is to write the literal SQL
first, test it in your DB, then create the select() expression to match.