Lecture 9: SQL SELECT PART 3 & RA Flashcards

1
Q

example of cartesian product query

A

SELECT c.clientNo, c.fname, c.lname, v.clientNo, v.propertyNo, v.viewDate, v.comment
FROM client c, viewing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are multi-table queries?

A
  • Natural Join or Simple Join
  • one of the most difficult operations to implement efficiently
  • Must use join if result columns come from more than one table
  • perform join, include more than one table in from clause separated by comma
  • include WHERE clause to specify join columns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Eg of three table join

A

SELECT b.branchNo, b.city, s.staffNo, fName, lName, propertyNo
FROM branch b, staff s, propertyForRent

WHERE b.branchNo = s.branchNo AND
s.staffNo = p.staffNo

ORDER BY b.branchNo, s.staffNo, propertyNo;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

list the procedures for generating results of a join

A
  1. Form Cartesian product of the tables named in FROM clause
  2. If there is a WHERE clause, apply the search condition to each row of the product table, retaining those rows that satisfy the condition
  3. For each remaining row, determine value of each item in SELECT list to produce a single row in result table
  4. If DISTINCT has been specified, eliminate any duplicate rows from the result table
  5. If there is an ORDER BY clause, sort result table as required
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are outer joins?

A

outer join operations retain rows that do not satisfy the join condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are left outer joins?

A

includes rows of first (left) table unmatched with rows from second right table

columns from second table are filled nulls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are right outer joins?

A
  • right outer joins includes those two rows of second (right) table that are unmatched with rows from first (left) table
  • columns from first table are filled with NULLS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are full outer joins?

A
  • includes rows that are unmatched in both tables

* unmatched columns are filled with nulls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ANY and ALL

A
  • any and all may be used with subqueries that produce a single column of numbers
  • ALL = true when values produced by subquery
  • ANY = true if it is satisfied by any values produced by subquery
  • if subquery empty, all returns true, any returns false
  • some may be used in place of any
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Exists and Not exists

A

EXISTS and NOT EXISTS are for use only with subqueries

Produce a simple true/false result

True if and only if there exists at least one row in result table returned by subquery

False if subquery returns an empty result table

NOT EXISTS is the opposite of EXISTS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

List the relational algebra

A
theta join
equijoin
natural join
outer join
left outer join

also division command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly