1

My MySQL version is 5.6.
I have a MySQL query that I getting error and need help to understand what I am doin wrong.

Here is the query:

select images.thumbnail16x9_file,
       images.square_file,
       RANK() OVER (ORDER BY images.timestamp desc) rank
from images 
where images.media_id = 875021;

This is the error message:

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 '(ORDER BY images.timestamp ) rank
from images where images.media' at line 3

I get result back if I do:

select images.thumbnail16x9_file,
       images.square_file
from images 
where images.media_id = 875021 ;

Any insight?

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
VictorGram
  • 2,521
  • 7
  • 48
  • 82

2 Answers2

2

Seeing as you mentioned running MySQL 5.6, I compared the documentation for 5.6 with that of 8.0 and noticed that the RANK() function might not be available in MySQL 5.6.

The documentation for MySQL 5.6 exists here, and for 8.0 exists here.

Searching for the RANK() function in 8.0 returns a section called Window Function Descriptions that seems to cover the RANK() function, while performing the same search in 5.6 doesn't seem to return anything about the function. I'm not 100% sure about this, but would definitely try to find a reference to the RANK() function in the 5.6 documentation for clarification.

-1

The alias rank is a reserved word in Mysql, so you should choose another name for it.

mqyg
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 12 '22 at 02:53