Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

441
Views
Why doesn't ORDER BY 'id' 'desc' return a syntax error?

I was testing some apparently wrong code and was quite sure it should return a syntax error. But it didn't. The following query works without errors (albeit doesn't sort the table either, which at least meets my expectations):

SELECT * FROM dummy ORDER BY 'id' 'desc';

Interestingly, that

SELECT * FROM dummy ORDER BY id 'desc';

does produce a syntax error.

How does MySQL interpret two strings after ORDER BY? What does it take these strings for? Here is the MCVE

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

SELECT * FROM dummy ORDER BY 'id' 'desc';

evaluates to

SELECT * FROM dummy ORDER BY 'iddesc';

I.e. ORDER BY a (constant) string literal - which doesn't affect the ORDER BY at all.

Note: This is ANSI/ISO SQL standard, a character literal can be built up by several parts, without having explicit concatenation.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!