Jump to content


Photo

Query ORDER BY


  • Please log in to reply
2 replies to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 21 September 2006 - 12:04 AM

Hi all

I have a database which holds a top ten, I have one field called `position` and another called `type`, there are 10 rows with a `type` of 1 and each row has a value in the field called `position` which range from 0-9, within this table, I also have another 10 rows with a `type` of 2 and each row has a value in the field called `position` which range from 0-9.

The table looks like

id    position    type

1      0        2
2      1        2
3      2        2
4      3        2
5      4        2
6      5        2
7      6        2
8      7        2
9      8        2
10      9        2
11      0        1
12      1        1
13      2        1
14      3        1
15      4        1
16      5        1
17      6        1
18      7        1
19      8        1
20      9        1

I run a query which looks like

$sql = "SELECT * FROM top10 ORDER BY position ASC LIMIT 10";

It supposed to return the rows in the following order

position    type

0              2
0              1
1              2
1              1
2              2
2              1
3              2
3              1
4              2
4              1

but for some reason, it is returning the results as

0              2
0              1
1              1
1              2
2              1
2              2
3              1
3              2
4              1
4              2

basically its supposed to show type 1 then type 2 then type 1 then type 2 then type 1 then type 2 and so on, so the results are mixed evenly.

Does that make sense? What am I doing wrong?

Thanks in advance

Dave

#2 Alteczen

Alteczen
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 September 2006 - 12:08 AM

I think you can just add another sort to it:  $sql = "SELECT * FROM top10 ORDER BY position, type ASC LIMIT 10";

#3 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 21 September 2006 - 12:16 AM

thank you thank you thank you




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users