Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

How does the following query works?

I have this query select * from customers order by country .. which I understood fine, because it will take into the account of the country attribute and gives the result in ascending order.. But how does the following one work

select * from customers order by country,id how this would work?

Changed category to development tools

1 Answer

Vince Brown
Vince Brown
16,249 Points

Hey Vamsi, For the SQL your data will be ordered twice, First the query will go through and order by country after that is completely through it will go back through and order by ID.

It might be easier to think of it like this if you have

SELECT * FROM products ORDER BY price, product_name

This query will go through and order all your products by price first, Then it comes back through and Orders all the subsets by name - So if any two products have the same price they would be ordered by product_name.

Hope this helps!