LearnWave
Learn it. Master it.

Querying and SQL Functions

Operations on relations

Find the result of set operations and Cartesian products.

Some operations combine two relations (tables). For union, intersection and difference, both tables must have the same number of attributes (columns), with the same domains (types of values).

  • UNION: rows that are in either table; a row present in both is shown only once.
  • INTERSECT: rows that are in both tables.
  • MINUS: rows that are in the first table but not in the second.

For example, if one table lists students in a dance club and another lists students in a music club, INTERSECT gives those in both clubs, and MUSIC MINUS DANCE gives those only in music.

The Cartesian product (×) pairs every row of the first table with every row of the second.

  • Degree (number of columns) of the result = the sum of the two degrees.
  • Cardinality (number of rows) = the product of the two cardinalities.

Example: a table with 4 columns and 5 rows × a table with 2 columns and 3 rows gives degree 4 + 2 = 6 and cardinality 5 × 3 = 15. Pairs for ×, common rows for ∩.

Pairs for ×, common rows for ∩.

Practise this lesson

Questions that get harder as you improve, a Tutor that helps without giving the answer away, and progress you can see. Free for every learner.

No account, no email address. Opens the real product.