For test exercise we’ll use the PizzaDB. You can find link to the database script on GIT.
You don’t need to have a database installed to do these exercise, just use the prompts below.
In these exercise we’ll write some queries using either the Product or Customer tables.
Exercise #1
Select LastName, City, and PostalCode from the customer table in LastName order.
Hint: You can use the ORDER BY clause to sort the results.
Keep in mind the ORDER BY clause is after the FROM clause.
Exercise #2
You can use comparison operators on text values as well.
Select LastName, City, and PostalCode from Customer in order of City and LastName. The Last Names should be in descending order.
Hint: Add DESC to the end of a column to sort that column in descending order.
Exercise #3
What are the top five highest priced products? Use the product table and display the Product’s name and Price.
The biggest trick is ordering in descending order so that the LARGEST items are at the beginning of the result set.
If you wanted to write this query in SQL Server it would like like this: