Tutorial 5 Multi-table queries

advertisement
Tutorial 5
Multi-table queries
Tutorial 5 objectives
• Displaying Data from Multiple Tables
– [ ]Write SELECT statements to access data
from more than one table using equality and
non-equality joins
Using Northwind…
1.
2.
3.
4.
5.
6.
7.
Show the product Id, the product name, the category id and
the category name.
Show the customerID, company name and OrderId of all
customers who have orders.
Show the customer’s CompanyName and the first and last
name of any employee who has filled an order for that
customer.
Repeat 3 using the ‘distinct’ keyword straight after the word
select. Note the difference in the number of rows.
Show the companyname and the name of each product the
customer has ordered.
Repeat 5, ordering the result by companyname and
productname.
Repeat 6, using the ‘distinct’ keyword.
Northwind data model
Testing the joins
select customers.customerId,
CompanyName, orderId from
customers left join orders on
customers.customerID=orders.customerID
where orders.customerID is null
Download