Do You Want to Learn SQL?

Take our free eight day course, where I'll teach you in simple to understand English all you need to get started learning SQL.

-
DAYS
-
HOURS
-
MINUTES
-
SECONDS

Free Beginners SQL Course!

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.

/* Answer */
select LastName, City, PostalCode
from Customer
order by LastName

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.

/* Answer */
select LastName, City, PostalCode
from Customer
order by City, LastName desc

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.

/* Answer */
select ProductName, Price
from Product
order by Price desc
limit 5

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: