2

I'm trying to have a blog page order it's entries by the auto incremented unique ID given in descending order, it doesn't seem to allow it. It always appears in ascending order despite the SQL request as written below:

SELECT * FROM news_blog ORDER BY 'news_id' DESC

Is it because the news id is an Integar and therefore doesn't allow for ordering?

Dharman
  • 30,962
  • 25
  • 85
  • 135
SamesJeabrook
  • 1,387
  • 5
  • 17
  • 27
  • Cam you please post the description of your table in order for us to be able to help you. The fact that the news_id is an integer should not be an issue – Paraíso Nov 15 '13 at 14:09
  • news_id - int(11) - AUTO_INCREMENT blog_title - varchar(50) – SamesJeabrook Nov 15 '13 at 15:21
  • 1
    Does this answer your question? [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – mickmackusa Mar 20 '22 at 11:47

1 Answers1

11

If you want to escape column or table names use backticks, not quotes

SELECT * FROM news_blog
ORDER BY `news_id` DESC

SQLFiddle demo

When using quotes the DB thinks you want to sort by the static string 'news_id' which is not sorting at all since it is the same for a records.

juergen d
  • 201,996
  • 37
  • 293
  • 362