Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Module 10 - MySQL Queries

Customer Table Questions:


You may assume that the customers table has only the following fields for the purpose of this
exercise.

(CustomerID, Name, Address, City, Zip, Country)

If you wish you may create and query an actual table to verify that your answers are correct.

1. Get all the columns from the Customers table.

ANSWER: SELECT * FROM ‘customer’;

2. Write a statement that will select the City column from the Customers table.

ANSWER: SELECT `City` FROM `customer`;

3. Select all records where the City column has the value "Berlin".

ANSWER: SELECT * FROM `customer` WHERE City='Berlin'

4. Use the NOT keyword to select all records where City is NOT "Berlin".

ANSWER: SELECT * FROM `customer` WHERE City!='Berlin'

5. Select all records where the CustomerID column has the value 32.

ANSWER: SELECT * FROM `customer` WHERE CustomerID='32'

6. Select all records where the City column has the value 'Berlin' and the Zip column has the
value 12209.

ANSWER: SELECT * FROM `customer` WHERE City='Berlin' AND Zip='12209'

7. Select all records where the City column has the value 'Berlin', and also the records where the
City column has the value 'London'.

ANSWER: SELECT * FROM `customer` WHERE City='Berlin' AND City='London'

8. Select all records from the Customers table, sort the result alphabetically by the column City.

ANSWER: SELECT * FROM `customer` ORDER BY City


9. Select all records from the Customers table, sort the result reversed alphabetically by the
column City.

ANSWER: SELECT * FROM `customer` ORDER BY City DESC

10. Select all records from the Customers table, sort the result alphabetically, first by the column
Country, then, by the column City.

ANSWER: SELECT * FROM `customer` ORDER BY Country, City

11. Select all records from the Customers where the Zip column is empty.

ANSWER: SELECT * FROM `customer` WHERE Zip=NULL

12. Select all records from the Customers where the Zip column is NOT empty.

ANSWER: SELECT * FROM `customer` WHERE Zip!=NULL

13. Insert a new record in the Customers table.

ANSWER: INSERT INTO ‘customer’ VALUES #######;

14. Set the value of the City columns to 'Oslo', but only the ones where the Country column has
the value "Norway".

ANSWER HERE:

15. Update the City column of all records in the Customers table to 'Berlin'.

ANSWER HERE:

16. Update the City value to 'Pensacola' and the Country value to 'USA'.

ANSWER HERE:

17. Delete all the records from the Customers table where the Country value is 'Pensacola'.

ANSWER HERE:

18. Delete all the records from the Customers table.

ANSWER HERE:
Shopping Cart Project (Order and Item tables):
19. Write an SQL insert statement to insert an Order into the ORDER table

ANSWER HERE:

20. Write an SQL insert statement to insert an Item into the ITEM table (corresponding to the
order you just created).

ANSWER HERE:

You might also like