From the course: SQL Practice: Basic Queries
Solution: Get sorted data from a table - SQL Tutorial
From the course: SQL Practice: Basic Queries
Solution: Get sorted data from a table
- [Instructor] This code challenge uses just one of the tables in this database, the Customers table. This table has many columns, starting with the primary key of CustomerID and continuing with a whole bunch of different columns for first name, last name, and so on. In this challenge, you're asked to return just a few of the columns sorted by the last name and then the first name. The beginning code selects everything from the Customers table, and when you test the code with this solution, you'll get incorrect output and it'll show that you're returning everything in that database table sorted by the primary key, the CustomerID. Now I'm going to paste in my solution. This time, I'm only returning three columns: the FirstName, the LastName, and the Email column. I'm getting the data from the same table, the Customers table, but now I'm sorting the data by the LastName and then the FirstName columns. Notice that I specify asc for ascending on both columns. That isn't actually necessary because that's the default, but if you want to be explicit, you can put those in. And when I test my code, I get back the expected response, the same data but now sorted alphabetically. And this time, I'm only getting back to three requested columns: FirstName, LastName, and Email. So that's my solution to this challenge. What's yours?
Contents
-
-
-
Solution: Get sorted data from a table1m 35s
-
(Locked)
Solution: Retrieve data from multiple tables1m 29s
-
(Locked)
Solution: Retrieve data filtered on a range1m 41s
-
(Locked)
Solution: Retrieve aggregated data2m 12s
-
(Locked)
Solution: Get data filtered with a string pattern1m 31s
-
(Locked)
Solution: Find the most expensive order1m 55s
-
(Locked)
Solution: Find the average of orders2m 5s
-
-