
Jhomer Recometa
11/13/2004
CIT 381
HW 3
1. Which parts of the SQL SELECT statement are used to specify the relational
operations projection, selection, and join?
โ A projection operation produces a result table with only some of the
columns of its input table. In a SQL statement, this is represented by the
SELECT and FROM parameters.
โ A selection operation produces a result table with all of the columns of the
input table and only those rows of its input table that satisfy some criteria.
In a SQL statement, this is represented by the WHERE statement.
โ A join operation produces a result table by combining the columns of two
input tables. In a SQL Statement the join is produced with a combination
of the FROM, JOIN and ON statements.
2. Write an SQL query to find out which movies have been previously rented.
Include in your output title, accountId, dateRented, dateReturned, and cost.
Order the results by title (ascending) and then dateRented (descending) for each
title.
SELECT m.title, p.accountId, p.dateRented, p.dateReturned, p.cost
FROM (Video v INNER JOIN Movie m ON v.movieId = m.movieId)
INNER JOIN PreviousRental p ON p.videoId = v.videoId
ORDER BY m.title, p.dateRented DESC;
Movies โ Previously Rented
title accountId dateRented dateReturned cost
Animal House 201 1/14/2002 1/24/2002 $3.35
Annie Hall 101 1/15/2002 1/15/2002 $0.99
Annie Hall 201 12/9/2001 12/14/2001 $3.99
Annie Hall 102 12/1/2001 12/3/2001 $2.49
Annie Hall 101 1/13/2001 1/4/2001 $1.99
Duck Soup 111 1/1/2002 1/4/2002 $3.95
The Thirty-Nine Steps 101 12/9/2001 12/10/2001 $2.49
The Thirty-Nine Steps 111 12/4/2001 12/6/2001 $2.49