Oracle__9. Oracle 1Z0-051 Exam - Joins Flashcards
List the 2 main types of Joins?
- INNER2. OUTER
What is another name for simple join?
INNER
List the 3 types of OUTER joins?
- LEFT OUTER JOIN2. RIGHT OUTER JOIN3. FULL OUTER JOIN
What type of join returns all rows from multiple tables where the join condition is met?
INNER
Will this statement execute without errors? SELECT a.name, b.name, a.id FROM table1 a, table2 b WHERE a.id = b.id
Yes.This is an implicit Inner Join with aliases.
Rewrite the statement below using an INNER JOIN? SELECT a.name, b.name, a.id FROM table1 a, table2 b WHERE a.id = b.id
SELECT a.name, b.name, a.idFROM table1 aINNER JOIN table2 bON a.id = b.id
Rewrite the statement below using an INNER JOIN but add another join column named lastname in which is in both tables. Also add lastname to the select clause. SELECT a.name, b.name, a.id FROM table1 a, table2 b WHERE a.id = b.id
SELECT a.name, b.name, a.id, a.lastnameFROM table1 aINNER JOIN table2 bON a.id = b.idAND a.lastname = b.lastname
Rewrite the statement below using an INNER JOIN adding another table3 which has both an id and a lastname column. SELECT a.name, b.name, a.id, a.lastname FROM table1 a INNER JOIN table2 b ON a.id = b.id AND a.lastname = b.lastname
SELECT a.name, b.name, a.id, a.lastnameFROM table1 aINNER JOIN table2 bON a.id = b.idAND a.lastname = b.lastnameINNER JOIN table3 cON a.id = c.idAND a.lastname = c.lastnameNote: in this case the order of tables does not matter and table3 could be joined to table2 instead
Will this statement execute with errors? SELECt a.name, b.name, a.id FROM table1 a JOIN table2 b ON a.id = b.id
No[INNER] JOINThe keyword INNER is not necessary in Oracle.Also case letters do not matter in the keyword SELECt
What type of join is needed if you want all rows returned from the left table an only those rows that match the Join from the right table?
LEFT [OUTER] JOINThe keyword OUTER is not necessary in Oracle.
What type of join is needed if you want all rows returned from the right table an only those rows that match the Join from the left table?
RIGHT [OUTER] JOINThe keyword OUTER is not necessary in Oracle
What type of join will return all rows from both tables with nulls where the join condition is not met?
FULL [OUTER] JOINThe keyword OUTER is not necessary in Oracle
What 3 clauses of a SQL statement can have a subquery?
- SELECT2. FROM3. WHERE
If JOINING 2 tables would you use the ON clause or USING clause if you are joining fields with different names, but the same data types?
ON clause joins columns with different names, but the same data types.
If columns are joined with the ON clause and have the same name between the tables how are the columns differentiate in other clauses of the SQL statement?
Either a table prefix or a alias prefix will differentiate the columns that are the same names between different tables.Example using table prefix to differentiate:SELECT table1.id, table2.id, table1.code, table2.codeFROM table1JOIN table2ON table1.id = table2.idAND table1.code = table2.codeExample using aliases prefix to differentiate:SELECT a.id, b.id, a.code, b.codeFROM table1 aJOIN table2 bON a.id = b.idAND a.code = b.code
If columns are joined with the USING clause and have the same name between the tables how are the columns differentiate in other clauses of the SQL statement?
The columns defined in the USING at not prefixed.Example:SELECT id, codeFROM table1JOIN table2USING (id, code)
Inner Joins can use the JOIN..ON clause or the WHERE clause. What is the syntax of this statement using the WHERE clause to join. SELECT table1.id, table2.id, table1.code, table2.code FROM table1 JOIN table2 ON table1.id = table2.id AND table1.code = table2.code
SELECT table1.id, table2.id, table1.code, table2.codeFROM table1, table2WHERE table1.id = table2.idAND table1.code = table2.code