0% found this document useful (0 votes)
136 views

Untitled

This document provides instructions for several SQL queries using joins on sample database tables. The queries include: 1. An inner join to find titles related to a sales order using the titles and salesdetails tables. 2. A self join on the Authors table to find authors with the same zip code. 3. An inner join using a inequality to display orders shipped later than the sale date from the sales and salesdetails tables. 4. Left and right outer joins between the authors and publishers tables to return authors and publishers that match or do not match on city. 5. Right and left outer joins reversed from number 4 to return publishers and matching or non-matching authors based on city.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views

Untitled

This document provides instructions for several SQL queries using joins on sample database tables. The queries include: 1. An inner join to find titles related to a sales order using the titles and salesdetails tables. 2. A self join on the Authors table to find authors with the same zip code. 3. An inner join using a inequality to display orders shipped later than the sale date from the sales and salesdetails tables. 4. Left and right outer joins between the authors and publishers tables to return authors and publishers that match or do not match on city. 5. Right and left outer joins reversed from number 4 to return publishers and matching or non-matching authors based on city.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL Assignment 2 Queries using Joins

1. Inner or Equijoin
Using the title and salesdetails tables, write a query that finds titles related
to sales order number 14. The field name is sonum. You may want to use t as a
n alias for titles table and sd as a alias for the salesdetail table. You ident
ify aliases in the from clause. (202) Also draw a Venn diagram that represent
your results.

2. Self join (Inner join that compares values within a column of a single tabl
e)
Using the table Authors, find out which authors in Oakland, CA have exactly the
same zip code. You must use aliases to identify the table twice. Use au1 and a
u2. I will get you started
Select au1.au_fname, au1.au_lname, au1.zip
From authors au1, authors au2 (line where aliases are identifi
ed)
Where

Now the results will have some repeat information. So to eliminate the duplicat
e row in the results use “distinct” just after the select command. (206-7) Draw a
Venn diagram that represents your results.
3. Inner join but based on an inequality
Using the tables sales and salesdetails, write a query that displays orders that
were shipped on a date later than the sale. Use a < operater. Remember you mu
st match up the records using sonum in each table so that you can compare sales
date to shipping date. (204)
Outer joins in our sql-92 version use the “where” clause to indicate outer joins.
A left outer join is indicated by “*=” and a right outer join is indicated by a “=*”.
4. a. (Left outer Join) Using the authors and publishers tables, write a query
that yields all the authors names (first and last) and only the publishers that
a located in a city where an author lives. Make the query show the city name an
d publisher. (211) Also show the result using a Venn diagram.
4. b. Now see if you can write the query that gives just the authors and their c
ities that have no match with publisher cities. Also show the result using a Ve
nn diagram.
5. a. (Right outer join) Write a query that yields all the publishers and the
authors that live in the same city as a publisher. Make the query show the cit
y name and authors names. (212). Also show the result using a Venn Diagram
5. b. Now see if you can write the query that just gives the publishers and the
ir cities that have no match with city in which an author lives. Also show the
result using a Venn Diagram

You might also like