What is the result of performing a Cartesian product (cross join) between two tables, each having 3 rows?
Remember, Cartesian product pairs every row of the first table with every row of the second table.
Cartesian product multiplies the number of rows from both tables. So 3 rows × 3 rows = 9 rows.
Which type of join returns only the rows where there is a match in both joined tables?
This join excludes rows without matching keys in either table.
INNER JOIN returns only rows with matching values in both tables.
Given two tables:
Table A has 2 rows with IDs 1 and 2.
Table B has 3 rows with IDs 2, 3, and 4.
What will be the number of rows returned by the query: SELECT * FROM A LEFT JOIN B ON A.ID = B.ID;?
LEFT JOIN returns all rows from the left table, matching rows from the right, or NULL if no match.
Table A has 2 rows, so LEFT JOIN returns 2 rows. One row matches ID 2 in B, the other has NULLs for B columns.
What is the main difference between INNER JOIN and FULL OUTER JOIN results?
Think about how unmatched rows are handled in each join type.
INNER JOIN returns only rows with matches in both tables. FULL OUTER JOIN returns all rows from both tables, filling NULLs where no match exists.
Consider two tables:
- Table X has 4 rows.
- Table Y has 5 rows.
If you perform a CROSS JOIN between X and Y, then INNER JOIN the result with a third table Z having 3 rows on a condition that matches exactly 2 rows from the CROSS JOIN result per row in Z, how many rows will the final result have?
Calculate the size of the CROSS JOIN first, then multiply by the matching rows per Z row.
CROSS JOIN of X and Y produces 4 × 5 = 20 rows.
Each of the 3 rows in Z matches exactly 2 rows from this 20-row set.
So final rows = 3 × 2 = 6 rows.
The INNER JOIN filters to only these matching rows.