Michael St Clair
Michael St Clair

Reputation: 6635

mysql won't order by INT

I have set up a table with a column called order. I made sure it is set as INT. I can't seem to get the results to list in order. I currently have 5 rows with numbers 1-5 in a random order in those rows. However, I can't get those rows to go in order. Maybe I am doing this completely wrong, as I am new to MySql. Here is my query

SELECT * FROM faq ORDER BY 'order'

Upvotes: 0

Views: 296

Answers (5)

Sathish D
Sathish D

Reputation: 5044

You should use backtik not quotes:

SELECT * FROM faq ORDER BY `order`;

Refer: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

Upvotes: 0

viraptor
viraptor

Reputation: 34205

You're quoting 'order' like a string, so the sorting will be done by the value order itself (a string) rather than by the column. Change them to backticks instead.

Upvotes: 1

Jehad Keriaki
Jehad Keriaki

Reputation: 545

You should use the back-tick, not the quote:

SELECT * FROM faq ORDER BY `order`

Upvotes: 3

Robbert
Robbert

Reputation: 6592

You need to use backticks in mysql, not quotes.

SELECT * FROM faq ORDER BY `order`

Upvotes: 3

WWW
WWW

Reputation: 9870

You need:

SELECT * FROM faq ORDER BY `order`

You're using single-quotes in your example. MySQL uses backticks for wrapping table names, field names, etc. You need to use backticks in this case because order is a reserved word in MySQL.

Upvotes: 2

Related Questions