SQL Examples
SQL Examples
1. Write a SQL statement to extract the customer_ID and customer name for everyone who
has ordered a Smarties cookie, in order of customer name.
2. Write a SQL statement to extract the customer_ID and item_ordered for everyone who’s
ordered more than 5 cookies.
2i. Write the results of this SQL Statement.
3. Write a SQL Statement to update the item_ordered of chocolate chip to CC where at least
3 have been ordered. 3
3i. Write a SQL Statement to update the item_ordered of Ginger nut to nn where only one
has been ordered.
4. Write a SQL Statement for a new customer: CustomerName: Bertie, Item_ordered
Oatmeal, Quantity 2.
1. Write a SQL statement to extract the customer_ID and customer name for everyone who
has ordered a Smarties cookie, in order of customer name.
SELECT field names separated by comma FROM table number WHERE condition ORDER BY
field name.
2. Write a SQL statement to extract the customer_ID and item_ordered for everyone who’s
ordered more than 5 cookies.
Write INSERT INTO, table name, fields you’re wanting to add into (in brackets), VALUES,
items you want adding in – remembering “” for strings.
ANSWERS:
1. Write a SQL statement to extract the customer_ID and customer name for everyone who
has ordered a Smarties cookie, in order of customer name.
SELECT customer_ID, customerName FROM Cookie_Orders WHERE item_ordered =
“Smarties” ORDER BY customerName.
2. Write a SQL statement to extract the customer_ID and item_ordered for everyone who’s
ordered more than 5 cookies.