eindoofus Posted August 18, 2010 Share Posted August 18, 2010 I took the following query out of the book "Peachprint Press PHP 6 and MySQL 5 for Dynamic Web Sites 2007": SELECT first_name, last_name FROM users ORDER BY last_name ASC, first_name ASC; I don't understand the point of having "first_name ASC" at the end. As far as I know SQL organizes the table by rows and maintains the relationship within each row. Doesn't SQL just ignore any statement that would follow "last_name ASC"? If it didn't then the relationships within a table would get scrambled, wouldn't they? Would there ever be a reason to include more than one statement after an "ORDER BY"? Quote Link to comment https://forums.phpfreaks.com/topic/211103-does-this-query-from-my-book-make-any-sense/ Share on other sites More sharing options...
Maq Posted August 18, 2010 Share Posted August 18, 2010 It orders the results by last_name, but if there are multiple results with the same last name there is a secondary ordering by the first name. Quote Link to comment https://forums.phpfreaks.com/topic/211103-does-this-query-from-my-book-make-any-sense/#findComment-1100917 Share on other sites More sharing options...
eindoofus Posted August 18, 2010 Author Share Posted August 18, 2010 I can't believe I didn't think of that. It's so obvious now. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/211103-does-this-query-from-my-book-make-any-sense/#findComment-1100930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.