Complete the code to select all customers who have placed an order using a subquery.
SELECT customer_id FROM orders WHERE customer_id IN (SELECT [1] FROM customers);The subquery must select customer_id from the customers table to match the outer query's customer_id.
Complete the code to join customers and orders tables to get customer names and their order dates.
SELECT c.name, o.order_date FROM customers c [1] orders o ON c.customer_id = o.customer_id;An INNER JOIN returns only customers who have orders, matching the requirement.
Fix the error in the query to find customers who have not placed any orders using a subquery.
SELECT name FROM customers WHERE customer_id [1] (SELECT customer_id FROM orders);To find customers without orders, use NOT IN to exclude those with matching orders.
Fill both blanks to write a query that lists customers and their order counts, including customers with zero orders.
SELECT c.name, COUNT(o.order_id) AS order_count FROM customers c [1] JOIN orders o ON c.customer_id [2] o.customer_id GROUP BY c.name;
A LEFT JOIN includes all customers even if they have no orders. The join condition uses = to match customer IDs.
Fill all three blanks to write a query that selects customers with orders after 2023-01-01 using a JOIN and a WHERE filter.
SELECT c.name, o.order_date FROM customers c [1] JOIN orders o ON c.customer_id [2] o.customer_id WHERE o.order_date [3] '2023-01-01';
An INNER JOIN returns customers with matching orders. The join condition uses = to match IDs. The WHERE clause filters orders after 2023-01-01 using >.