Skip to main content
Participant
July 11, 2006
Question

Query String - Sort by 2 Keys

  • July 11, 2006
  • 1 reply
  • 283 views
Hi,

I am using a MySQL database with php through DW8. I have a small problem ok. I have a football fixtures table with different age groups playing matches so I use the following query string to extract the resultset

"Select * from Fixtures sort by age ASC;"

This is fine ok, and it returns me all the e.g. age 10 matches for the next year. But can i add anything to the code to make it sort within the ages then by "fixture_id" ascending? e.g. something like this:
SELECT * from fixtures sort by age ASC AND fixture_id ASC;
I hope I am being clear enough, in other words, is there a way to sort by one key and then sort within those results by another key?

Stone



This topic has been closed for replies.

1 reply

Inspiring
July 12, 2006
stoneygossard wrote:
> I am using a MySQL database with php through DW8. I have a small problem ok. I
> have a football fixtures table with different age groups playing matches so I
> use the following query string to extract the resultset
>
> "Select * from Fixtures sort by age ASC;"
>
> This is fine ok

Amazing, because that's not correct MySQL syntax. It should be:

SELECT * FROM Fixtures
ORDER BY age ASC

> But can i add anything to the code to make it sort within the ages then
> by "fixture_id" ascending? e.g. something like this:
> SELECT * from fixtures sort by age ASC AND fixture_id ASC;

Yes:

SELECT * FROM Fixtures
ORDER BY age ASC, fixture_id ASC

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Inspiring
July 12, 2006
stoneygossard wrote:
> Thanks, how simple was that!

Erm, pretty simple. I wish all questions were as easy as that! ;)

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/