Complete the code to select all columns from table1 and matching rows from table2 using a RIGHT JOIN.
SELECT * FROM table1 [1] table2 ON table1.id = table2.id;The RIGHT JOIN returns all rows from the right table (table2), and the matched rows from the left table (table1). If there is no match, NULLs appear for left table columns.
Complete the code to get all rows from the right table and matching rows from the left table where the right table's status is 'active'.
SELECT * FROM users [1] orders ON users.user_id = orders.user_id WHERE orders.status = 'active';
The RIGHT JOIN ensures all rows from orders (right table) are included, even if no matching users row exists. The WHERE clause filters for active orders.
Fix the error in the query to correctly perform a RIGHT JOIN between employees and departments on department_id.
SELECT employees.name, departments.name FROM employees [1] departments ON employees.department_id = departments.department_id;The query needs a RIGHT JOIN to include all departments even if no employee belongs to them.
Fill both blanks to select all customers and their orders, including customers without orders, using RIGHT JOIN and aliasing.
SELECT o.order_id, c.customer_name FROM orders AS [1] [2] customers AS c ON o.customer_id = c.customer_id;
Alias orders as o and use RIGHT JOIN to include all customers even if they have no orders.
Fill all three blanks to create a RIGHT JOIN query that selects product names and their categories, including categories without products.
SELECT p.product_name, c.category_name FROM products AS [1] [2] categories AS [3] ON p.category_id = c.category_id;
Alias products as p, use RIGHT JOIN to include all categories, and alias categories as c.