0
0
PostgreSQLquery~5 mins

LEFT JOIN and RIGHT JOIN in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does a LEFT JOIN do in SQL?
A LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there is no match, the result will contain NULL for columns from the right table.
Click to reveal answer
beginner
What is the difference between LEFT JOIN and RIGHT JOIN?
LEFT JOIN returns all rows from the left table and matching rows from the right table. RIGHT JOIN returns all rows from the right table and matching rows from the left table.
Click to reveal answer
beginner
In a RIGHT JOIN, what happens if there is no matching row in the left table?
If there is no matching row in the left table, the result will still include the row from the right table, but columns from the left table will be NULL.
Click to reveal answer
intermediate
Write a simple SQL query using LEFT JOIN to combine two tables: employees and departments.
SELECT employees.name, departments.department_name FROM employees LEFT JOIN departments ON employees.department_id = departments.id;
Click to reveal answer
intermediate
Why might you use a LEFT JOIN instead of an INNER JOIN?
You use LEFT JOIN when you want to keep all rows from the left table even if there is no matching row in the right table. INNER JOIN only returns rows with matches in both tables.
Click to reveal answer
What will a LEFT JOIN return if there is no matching row in the right table?
AAll rows from the right table
BNo rows
COnly rows with matching keys
DAll rows from the left table with NULLs for right table columns
Which JOIN returns all rows from the right table and matching rows from the left table?
ALEFT JOIN
BRIGHT JOIN
CINNER JOIN
DFULL JOIN
If you want to keep all employees even if they don't belong to a department, which JOIN should you use?
ALEFT JOIN
BRIGHT JOIN
CINNER JOIN
DCROSS JOIN
What will happen if you use RIGHT JOIN but the right table has no rows?
AResult will be empty
BAll rows from left table returned
CAll rows from right table returned
DError occurs
Which JOIN type can be thought of as the opposite of LEFT JOIN?
AINNER JOIN
BFULL JOIN
CRIGHT JOIN
DCROSS JOIN
Explain in your own words how LEFT JOIN works and when you would use it.
Think about keeping all your friends in a list even if some don't have phone numbers.
You got /4 concepts.
    Describe the difference between LEFT JOIN and RIGHT JOIN with an example.
    Imagine two lists: one is your friends, the other is their phone numbers.
    You got /4 concepts.