tags:

views:

48

answers:

2

If i have a sql table with column like this
id version subversion
1 1 0
1 1 2
1 2 0
1 2 1

I want to get the latest version, in this case is 2.1.

What should I do?

+4  A: 
SELECT TOP 1 * FROM [Versions] ORDER BY [version] DESC, [subversion] DESC

should work fine... It works in MySQL atleast, and this is the basic MSSQL translation.

For reference, since the edit history isn't shown yet, my original query was:

SELECT * FROM [Versions] ORDER BY [version] DESC, [subversion] DESC LIMIT 1

Apparently MSSQL doesn't have the limit clause though, only some workarounds.

Matthew Scharley
for MSSQL replace the Limit Clause at the end withSelect top 1
cmsjr
+1  A: 
SELECT TOP 1 * FROM table ORDER BY version DESC, subversion DESC
Abtin Forouzandeh