0
0
PostgreSQLquery~10 mins

NATURAL join and its risks in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to perform a natural join between tables employees and departments.

PostgreSQL
SELECT * FROM employees [1] departments;
Drag options to blanks, or click blank then click option'
AINNER JOIN ON
BCROSS JOIN
CLEFT JOIN
DNATURAL JOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using INNER JOIN without ON clause causes syntax error.
Using CROSS JOIN returns Cartesian product, not matching rows.
2fill in blank
medium

Complete the code to select employee names and their department names using NATURAL JOIN.

PostgreSQL
SELECT employees.name, departments.name FROM employees [1] departments;
Drag options to blanks, or click blank then click option'
ANATURAL JOIN
BJOIN ON employees.dept_id = departments.id
CLEFT JOIN ON employees.dept_id = departments.id
DCROSS JOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using JOIN ON without specifying the join condition.
Using CROSS JOIN which returns all combinations.
3fill in blank
hard

Fix the error in the query that uses NATURAL JOIN but returns unexpected results due to extra matching columns.

PostgreSQL
SELECT * FROM orders [1] customers ON orders.customer_id = customers.id;
Drag options to blanks, or click blank then click option'
ANATURAL JOIN
BINNER JOIN
CLEFT JOIN
DCROSS JOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using NATURAL JOIN when tables have multiple columns with the same name but different meanings.
Using CROSS JOIN which returns all rows combined.
4fill in blank
hard

Fill both blanks to create a query that avoids NATURAL JOIN risks by specifying join columns explicitly.

PostgreSQL
SELECT * FROM sales [1] customers [2] sales.customer_id = customers.id;
Drag options to blanks, or click blank then click option'
AINNER JOIN
BLEFT JOIN
CON
DUSING
Attempts:
3 left
💡 Hint
Common Mistakes
Using NATURAL JOIN which can join on unintended columns.
Using USING keyword without matching column names.
5fill in blank
hard

Fill all three blanks to write a safe join query selecting employee and department names, avoiding NATURAL JOIN risks.

PostgreSQL
SELECT e.name AS employee_name, d.name AS department_name FROM employees e [1] departments d [2] e.dept_id [3] d.id;
Drag options to blanks, or click blank then click option'
AINNER JOIN
B=
CON
DLEFT JOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using NATURAL JOIN which may join on unintended columns.
Using INNER JOIN when you want to keep all employees regardless of department.