I'm studying this SQL statement :
SELECT * FROM Customers
ORDER BY Country,CustomerName;
From this
How does it work that it orders by both country and CustomerName ? In my mind it just doesn't seem intuitive, i.e you order by either Country OR CustomerName but not both
You can also ORDER BY two or more columns, which creates a nested sort . The default is still ascending, and the column that is listed first in the ORDER BY clause takes precedence. The following query and Figure 3 and the corresponding query results show nested sorts.
The GROUP BY clause is used along with some aggregate functions to group columns with the same values in different rows. The group by multiple columns technique retrieves grouped column values from one or more database tables by considering more than one column as grouping criteria.
The ORDER BY clause applies to the final result set from the FULLSELECT statement. You can sort on either a single column or multiple columns. To sort on columns in a FULLSELECT statement that have the same ordinal value but are in different subordinate SELECT statements, the columns must have the same name.
Yes, it is possible to use MySQL GROUP BY clause with multiple columns just as we can use MySQL DISTINCT clause.
It orders by Country, but if some rows have the same Country, it orders them by CustomerName.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With