3.5 Equijoins, self-joins, and cross-joins Flashcards
What is the result of the following equijoin query?
SELECT Class.Name, Student.Name FROM Class INNER JOIN Student ON Student.Code = Class.Code;
The INNER JOIN returns rows where Student.Code matches Class.Code.
What is the result of the following equijoin query?
SELECT Name, Address FROM Buyer LEFT JOIN Property ON Price < MaxPrice;
Which join type is the following query?
Self-join
SELECT A.Name, B.Name FROM EmployeeManager A INNER JOIN EmployeeManager B ON B.ID = A.Manager;
What does the following cross-join query result in?
SELECT Model, Gigabytes FROM IPhone CROSS JOIN Storage;
CROSS JOIN generates all combinations of IPhone models and storage capacities.
What is the result of the following query?
SELECT Student.Name FROM Class INNER JOIN Student ON StudentGrade > AverageGrade AND Student.Code = Class.Code;
What is the primary use of equijoins?
To combine rows from tables where specified columns equal each other. Equijoins are typical for matching columns using the = operator.
Which SQL command combines two tables using conditions other than the equality operator?
Non-equijoin.
Non-equijoins utilize comparison operators other than =.
What does it mean when we refer to a ‘Cartesian product’ in SQL?
The result of a cross-join containing all possible row combinations. A Cartesian product pairs each row from the first table with every row from the second.
How do we distinguish same-table columns in a self-join?
Using aliases. Aliases act as prefixes to differentiate joined columns of the same table.
What is the result when using non-equijoin operators such as < and >?
Returns rows where the compare columns meet the specified non-equal condition.
Unlike equijoins, non-equijoins use operators like < or > instead of =.
Why are aliases necessary in self-joins?
To distinguish columns from the same tables. Aliases are used as prefixes to differentiate between the same table joined on itself.
Identify the join clause(s) usable in non-equijoin queries.
All JOIN clauses.
Non-equijoin conditions can apply with INNER, LEFT, RIGHT, or FULL JOINs.
What does a cross-join do without comparing columns?
Combines all rows from two tables into all possible pairs.
CROSS JOIN results in the Cartesian product of two tables.