forked from Code-the-Dream-School/sqlintro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql1.txt
43 lines (21 loc) · 1.62 KB
/
sql1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Hint: So that you can understand the schema, you may want to just do a simple select statement on each
table. For example, to see the schema for the Products table, you could do:
SELECT * FROM Products LIMIT 5;
1. Use an SQL SELECT statement to retrieve the first 10 rows of the Customer table, ordered by CustomerName.
Paste your SQL statement below:
2. Use an SQL Select statement to retrieve the names and prices for all products that cost less than $20.
Paste your SQL statement below:
3. Retrieve all employees whose last name starts with C. Paste your SQL statement below:
4. Retrieve the order ID and customer name for all orders where the customer name starts with A.
Here you will have to do a join of the Orders table and the Customers table. Paste your SQL
statement below.
5. Retrieve the list of customers, ordered by customer name, along with their order IDs. Note
that not every customer has an order, but be sure that you include those customers without orders
in the results of the query. Paste your SQL statement below.
6. Retrieve the list of customer names for customers that have no orders. There are two ways to do this
One is to use a subquery, as follows:
SELECT CustomerName FROM Customers WHERE CustomerID NOT IN (SELECT CustomerID FROM ORDERS);
This is a subquery -- we haven't talked about those. But, you can do the same thing with a left
join by comparing the OrderID column with NULL. Paste your SQL statement below.
7. Retrieve the OrderID and ProductName of every order for a product with Tofu in the name.
Paste your SQL statement below. You will have to join Orders, OrderDetails, and Products.