Jump to content

[SOLVED] Sort by multiple fields (mysql)


Darkmatter5

Recommended Posts

I have a dropdown list that's dynamically constructed from a MySQL query.  There are 3 fields I am currently sorting by:

 

SELECT client_id, first_name, last_name, company_name
FROM $dbname.clients
ORDER BY last_name ASC, first_name ASC, company_name ASC

 

I'm wanting to now sort last_name and company_name together and also order first_name when last_name is being used to sort.  This sounds confusing, here's an example of a desired list.

 

ABC, Inc.

Bowling, John

Branch, Ltd.

Smith, John

Toff, Jerry

Toff, Mary

YYZ Rush, Inc.

 

As you can see the first, third and seventh entries are company_names.  The second, fourth, fifth and sixth entries are last_name with firstname.  Notice the fifth and sixth entries are the same last_name, but different first_names, but are grouped together by last_name and then subordered by first_name.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/129399-solved-sort-by-multiple-fields-mysql/
Share on other sites

Archived

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

×
×
  • 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.