0

I lost my notes on this section and cannot find any info on it anywhere. I know what the cartesian product is but I don't know what it means by common attribute or why that must be equal. say I said

SELECT *
FROM STUDENT,ENROLS

what is the common attribute here or would that be one of the rows within these?

Zombo
  • 1
  • 62
  • 391
  • 407

2 Answers2

1

When a Cartesian product is formed in an SQL query such as

SELECT table1.column1, table2.column2... FROM table1, table2

it is logically equivalent to an Inner Join in which the test condition -always- evaluates to true.

Thus, the resulting table will be a Cross Join (or Cartesian Product) in which every row from first table operand is combined with all the rows from the second table operand.

The Cartesian Product is not formed by checking any test condition or common attribute, but it can be subsequently filtered by a test condition, eg. WHERE clause, just as an Inner Join can be.

scottb
  • 9,908
  • 3
  • 40
  • 56
0

No you don't need to check a common attribute. However if you don't do it, you get a cross join/outer join which might not what you want (combine every student with every enrollment). Typically such a cross join is then filtered for some conditions (like slot planning). But for questions like "list students with possible enrollments" or "list all enrolled students" a LEFT or RIGHT join is better.

See here for details: What is the difference between "INNER JOIN" and "OUTER JOIN"?

Community
  • 1
  • 1
eckes
  • 10,103
  • 1
  • 59
  • 71