Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query String - Sort by 2 Keys

New Here ,
Jul 11, 2006 Jul 11, 2006
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



TOPICS
Server side applications
286
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2006 Jul 11, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2006 Jul 12, 2006
Thanks, how simple was that!

Stone
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2006 Jul 12, 2006
LATEST
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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines