Syntax error in SELECT, in PHP [closed]

1

I'm putting the following code to make a query:

SELECT * FROM tabela ORDER BY coluna WHERE ROWNUM = 5

However, when I put this in my PHP, the following message appears:

  

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 'WHERE ROWNUM = 2' at line 1

    
asked by anonymous 27.01.2016 / 19:16

2 answers

7

WHERE comes before ORDER BY

SELECT * FROM tabela WHERE ROWNUM = 5 ORDER BY coluna

    
27.01.2016 / 19:18
5

Correct syntax is:

SELECT * FROM tabela WHERE ROWNUM =5 ORDER BY coluna
    
27.01.2016 / 19:18