sort varchr field

khaled salem
khaled salem used Ask the Experts™
on
I've ID Field varchar. when i use order by ID it sorted as
1
11
2
22
3
I'd like to sort this field as integer value ( in some reports)
1
2
3
11
22
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Use the CAST() function.

SELECT CAST(ID) AS ID
ORDER BY ID

http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html#function_cast
Commented:
Sorry should have been more specific CAST(ID AS SIGNED) AS ID
khaled salemSoftware Developer

Author

Commented:
can you explain in more details
khaled salemSoftware Developer

Author

Commented:
exactly

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial