Syntax error in SELECT, in PHP

Asked

Viewed 156 times

1

I am putting the following code to make a query:

SELECT * FROM tabela ORDER BY coluna WHERE ROWNUM = 5

However, when putting 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

2 answers

7


WHERE comes before ORDER BY

SELECT * FROM tabela WHERE ROWNUM = 5 ORDER BY coluna

  • 2

    Thank you. And I can’t believe I got stuck for 10 minutes because of all this nonsense.

  • 2

    Neither do I. But it happens.

  • 3

    I will wait the remaining time to accept the answer. Thank you again

  • Sometimes it’s just a damn parenthesis of a IF not closed on line 200 that keeps you awake because when the error is accused, accuse on line 5340, unexpected '{'... AFF

5

Correct syntax is:

SELECT * FROM tabela WHERE ROWNUM =5 ORDER BY coluna
  • 1

    Thank you. Silly mistake that cost me time

  • I’ve done that before, hehe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.