Jump to content

Archived

This topic is now archived and is closed to further replies.

CanMan2004

Query ORDER BY

Recommended Posts

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

[code]$sql = "SELECT * FROM top10 ORDER BY position ASC LIMIT 10";[/code]

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

Share this post


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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.