Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to select all columns from the employees table.
SQL
SELECT [1] FROM employees; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the table name instead of *
Using ALL which is not valid in SELECT
✗ Incorrect
The asterisk (*) selects all columns from the table.
2fill in blank
mediumComplete the code to join employees with departments on department_id.
SQL
SELECT employees.name, departments.name FROM employees [1] JOIN departments ON employees.department_id = departments.id; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OUTER JOIN without specifying LEFT or RIGHT
Using LEFT JOIN which includes unmatched rows
✗ Incorrect
INNER JOIN returns rows when there is a match in both tables.
3fill in blank
hardFix the error in the join condition to correctly join orders and customers.
SQL
SELECT orders.id, customers.name FROM orders INNER JOIN customers ON orders.[1] = customers.id; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using orders.id which is the order's own id
Using customers.name which is not an id
✗ Incorrect
The orders table has a foreign key customer_id that matches customers.id.
4fill in blank
hardFill both blanks to select employee names and their department names using a join.
SQL
SELECT employees.name, departments.[1] FROM employees [2] JOIN departments ON employees.department_id = departments.id;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting department id instead of name
Using LEFT JOIN which includes unmatched employees
✗ Incorrect
We select the department's name column and use INNER JOIN to get matching rows.
5fill in blank
hardFill all three blanks to select order id, customer name, and order date with a join.
SQL
SELECT orders.[1], customers.[2], orders.[3] FROM orders INNER JOIN customers ON orders.customer_id = customers.id;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting customer_id instead of order_date
Mixing up column names between tables
✗ Incorrect
We select order id, customer name, and order date columns to get full order info.