Page 1 of 1
MySQL ORDER BY problem...
Posted: Mon Dec 22, 2003 9:03 am
by Mark53
Hi everyone,
I've run a simple select :
select * from ... order by col2, col1
The result is :
col1 col2 ...
4 1
2 1
7 1
5 2
7 2
8 2
8 3
As you can see, the lines are sorted by col2, but NOT but col1. Why ?
Thanks for your help,
Mark
Posted: Mon Dec 22, 2003 9:13 am
by igoy
Try this
SELECT * FROM tablename ORDER BY col1 ASC
if you want to sorting order by
col1, why are you using
col2 in
ORDER BY clause?
Posted: Mon Dec 22, 2003 10:47 am
by JayBird
igoy wrote:if you want to sorting order by col1, why are you using col2 in ORDER BY clause?
Igoy:
You can sort by more than one column.
For example, sorting by col2, then by col1. If the data in some data in col2 is duplicated, for example, if there were 3 people with the surname jones, MySQL would then order each of the people by col1, their firstname.
Mark53:
Not sure why you are having that problem Mark53, what are the data types of the 2 columns.
Mark
Posted: Mon Dec 22, 2003 11:00 am
by igoy
Right Bech, I know we can sort by two or more columns. But guess Mark wanted to sort by col1.
anyways... even I was wondering why he is getting that problem.