0
0
SQLquery~10 mins

NULLs in JOIN conditions in SQL - Interactive Code Practice

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

Complete the code to join two tables on the column 'id'.

SQL
SELECT * FROM table1 JOIN table2 ON table1.id [1] table2.id;
Drag options to blanks, or click blank then click option'
A=
B!=
C<>
DLIKE
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '<>' which check for inequality.
Using 'LIKE' which is for pattern matching, not equality.
2fill in blank
medium

Complete the code to perform a LEFT JOIN that includes all rows from table1.

SQL
SELECT * FROM table1 [1] JOIN table2 ON table1.id = table2.id;
Drag options to blanks, or click blank then click option'
AINNER
BRIGHT
CLEFT
DFULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using INNER JOIN which excludes unmatched rows.
Using RIGHT JOIN which keeps all rows from the right table.
3fill in blank
hard

Fix the error in the JOIN condition to correctly handle NULL values in 'id'.

SQL
SELECT * FROM table1 JOIN table2 ON table1.id = table2.id OR (table1.id IS NULL [1] table2.id IS NULL);
Drag options to blanks, or click blank then click option'
AOR
BAND
CNOT
DXOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR which matches rows incorrectly when only one side is NULL.
Using NOT or XOR which are not logical for this condition.
4fill in blank
hard

Fill both blanks to join tables treating NULLs as equal in 'key' columns.

SQL
SELECT * FROM t1 JOIN t2 ON (t1.key [1] t2.key) OR (t1.key IS NULL [2] t2.key IS NULL);
Drag options to blanks, or click blank then click option'
A=
B!=
CAND
DOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=' for key comparison.
Using 'OR' instead of 'AND' for NULL checks.
5fill in blank
hard

Fill all three blanks to select rows where 'col1' matches or both are NULL, and 'col2' matches.

SQL
SELECT * FROM A JOIN B ON (A.col1 [1] B.col1 OR (A.col1 IS NULL [2] B.col1 IS NULL)) AND A.col2 [3] B.col2;
Drag options to blanks, or click blank then click option'
A=
B!=
CAND
DOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=' for comparisons.
Using 'OR' instead of 'AND' for NULL checks.