Jump to content

Query ORDER BY


CanMan2004

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.