Sams Teach Yourself SQL in 10 Minutes (Fifth Edition) includes challenges at the end of some lessons. Solutions to the challenges are presented here. Just keep in mind that there is rarely one solution to a SQL challenge, so if your solutions look different but produce the desired result, that’s ok.

Lesson 3

Write a SQL statement to retrieve all customer names (cust_name) from the Customers table, and display the results sorted from Z to A.


SELECT cust_name
FROM Customers
ORDER BY cust_name DESC;
Category: Lesson 3

Write a SQL statement to retrieve customer id (cust_id) and order number (order_num) from the Orders table, and sort the results first by customer id, and then by order date in reverse chronological order.


SELECT cust_id, order_num
FROM Orders
ORDER BY cust_id, order_date DESC;
Category: Lesson 3

Our fictitious store obviously prefers to sell more expensive items, and lots of them. Write a SQL statement to display the quantity and price (item_price) from the OrderItems table, sorted with the highest quantity and highest price first.


SELECT quantity, item_price
FROM OrderItems
ORDER BY quantity DESC, item_price DESC;
Category: Lesson 3

What is wrong with the following SQL statement? (Try to figure it out without running it):

SELECT vend_name,
FROM Vendors
ORDER vend_name DESC;

There should not be a comma after vend_name (a comma is only used to separate multiple columns), and BY is missing after ORDER.

Category: Lesson 3

Load More