Category Archives: SQL

Uniqueness Tests

🞑 Can test whether a nested query generates any duplicate tuples 🞑 UNIQUE (...) 🞑 NOT UNIQUE (...) 🞑Not widely implemented 🞑 Expensive…
Continue reading

Set Comparison Tests (3)

¨  Example: “Find branches with assets greater than all branches in Brooklyn.” SELECT branch_name FROM branch WHERE assets > ALL ( SELECT assets…
Continue reading

Set Comparison Tests (2)

¨  General form of test: attr compare_op SOME ( subquery ) 🞑 Can use any comparison operation = SOME is same as IN…
Continue reading

Set Comparison Tests

¨  Can compare a value to a set of values 🞑 Is a value larger/smaller/etc. than some value in the set? ¨  Example:…
Continue reading

Correlated Subqueries (2)

¨  Many correlated subqueries can be restated using a join or a Cartesian product 🞑 Often the join operation will be much faster…
Continue reading

Correlated Subqueries

“Find customers with an account but not a loan.” SELECT DISTINCT customer_name FROM depositor d WHERE NOT EXISTS ( SELECT * FROM borrower…
Continue reading

Empty-Set Tests (2)

“Find customers with an account but not a loan.” SELECT DISTINCT customer_name FROM depositor d WHERE NOT EXISTS ( SELECT * FROM borrower…
Continue reading

Empty-Set Tests

¨  Can test whether or not a subquery generates any results at all EXISTS (...) NOT EXISTS (...) ¨  Example: “Find customers with…
Continue reading

Set Membership Tests (2)

IN (...) and NOT IN (...) support subqueries that return multiple columns (!!!) ¨  Example: “Find the ID of the largest loan at…
Continue reading

Set Membership Tests

Can use IN (...) and NOT IN (...) for set membership tests ¨  Example: 🞑 Find customers with both an account and a…
Continue reading