Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MySql version 3.5.2.2


Fail to run this query.
SQL
select *
from (
select *, row_number() over (partition by `Column1` order by `Column2` desc) VersionRank from Table1
 ) T
 where `VersionRank` = 1


Error Ocurred:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(partition by `Column1` order by `Column2` desc) VersionRank from Table1' at line 3
Posted
Comments
Richard Deeming 12-Jan-15 9:34am    
I don't think MySql supports the row_number function. The only results I can see on Google are describing how to emulate it with a variable - for example, http://blog.sqlauthority.com/2014/03/08/mysql-generating-row-number-for-each-row-using-variable/[^]

EDIT: Whoops, just noticed digimanus' updated answer.

1 solution

Only in MSSQL:
SQL
SELECT *
FROM (
		SELECT row_number() over (partition by Column1 order by Column2 desc) VersionRank, * 
		FROM Table1
 ) T
 WHERE T.VersionRank = 1


for MySQL read this[^]
 
Share this answer
 
v2
Comments
CHill60 12-Jan-15 9:30am    
Good spot
DoingWork 12-Jan-15 10:08am    
Error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(partition by Column1 order by Column2 desc) VersionRank, * FROM table1 at line 3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900