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.
Write a SQL statement to retrieve all customer ids (cust_id) from the Customers table.
SELECT cust_id FROM Customers;
The OrderItems table contains every item ordered (and some were ordered multiple times). Write a SQL statement to retrieve a list of the products (prod_id) ordered (not every order, just a unique list of products). Here’s a hint, you should end up with seven unique rows displayed.
SELECT DISTINCT prod_id FROM OrderItems;
Write a SQL statement that retrieves all columns from the Customers table, and an alternate SELECT that retrieves just the customer id. Use comments to “comment out” one SELECT so as to be able to run the other. (And of course, test both statements).
SELECT * # SELECT cust_id FROM Customers;