Jump to content

[SOLVED] Multiple query output filters


Bizty

Recommended Posts

This may have a rather simple solution but seeing I've been coding for the good part of 2 days of 10 hour sessions I've roasted my brain.

 

Basicly I have a table with 2 data-lables.

 

for simplicity I'll make a simple illustration.

 

someTable

id,

name,

age

 

some simple data (id, name, age):

 

1, Dennis, 24

2, Peter, 13

3, Hans, 49

4, Andy, 23

5, Marcus, 29

6, JohnDoe, 58

 

Now I want my output to be sorted by the 'id':

 

mysql_query("SELECT * FROM someTable ORDER BY id");

 

further I want my ORDERED output sorted by age, how do I do that?

 

Hope you get it, pretty smashed atm, so might be a poor example.

 

Link to comment
Share on other sites

ORDER BY age, id

 

Do you want to order by the age, but if there are multiple records for that age, order that subset by id?

 

If you order by id first it's just going to order by id and nothing else.

Link to comment
Share on other sites

Ok, gonna try and take the example from what I am working on the ORDER BY id, age - didn't quite work.

 

I have a table:

 

id,

player_rank,

player_roll

 

lets say I have 30 entries here, 30 different players. Firstly, I want them listed by the player_rank DESC so ie:

 

10 players with the rank 1-10 ORDER BY player_rank DESC

10
9
8
7
6
5
4
3
2
1

 

The player_rank is changeing upon certain events, the important thing is that they can be equal, which is why I have player_roll aswell, lets say we have these 10 players with these player_rank values and player_roll values

 

player_rank(player_roll)
-----------------------
10(58)
9(43)
9(97)
7(100)
6(23)
6(84)
3(41)
2(95)
2(13)
1(1)

 

Now thats ordered by the player_rank allright, but I want it to order the player_roll where it's equal, again DESC, so it should look like this:

 

player_rank(player_roll)
-----------------------
10(58)
9(97)
9(43)
7(100)
6(84)--\
           -----84 is higher than 23, hence the ORDER BY player_roll DESC puts it first.
6(23)--/
3(41)
2(95)
2(13)
1(1)

 

Much like Maq suggested (I think), cheers for all the help so far it's superb that a hat like me can get a hand sometimes :)

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.