Skip to content
Advertisement

Sort by last name and first name

I have a small little problem. I am have a drop down list that displays all of our customers names. As of right now, the list is sorted by last name (A-Z). But for example, there are 250 people with the last name “Smith”. What I need is a way that the last name of each customer to stay the way it is but I need the first names to be listed alphabetically as well. Here is an example:

Customer #1 - Smith, Jean
Customer #2 - Smith, Allen
Customer #3 - Smith, Davey

What I would like is this:

Customer #1 - Smith, Allen
Customer #2 - Smith, Davey
Customer #3 - Smith, Jean

Here is how I am pulling the list now:

SELECT customer_id, first_name, last_name FROM customers ORDER BY last_name

Advertisement

Answer

Adjust your SQL statement, add the ORDER BY clause with the appropriate field names:

ORDER BY last_name ASC, first_name ASC

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement