Complete the code to start a CTE named 'first_cte'.
WITH [1] AS (SELECT * FROM employees)The WITH clause starts a CTE, and you must name it. Here, 'first_cte' is the correct CTE name.
Complete the code to add a second CTE named 'second_cte' after the first one.
WITH first_cte AS (SELECT * FROM employees), [1] AS (SELECT * FROM departments)When defining multiple CTEs, separate them with commas and give each a unique name. Here, 'second_cte' is the correct name for the second CTE.
Fix the error in the query by completing the code to select from both CTEs.
WITH first_cte AS (SELECT id, name FROM employees), second_cte AS (SELECT id, dept FROM departments) SELECT f.name, s.dept FROM [1] f JOIN second_cte s ON f.id = s.id;The main query must select from the CTE names, not the original tables. Here, 'first_cte' is the correct CTE to join with 'second_cte'.
Fill both blanks to create two CTEs and select from them.
WITH [1] AS (SELECT id, salary FROM employees), [2] AS (SELECT id, bonus FROM bonuses) SELECT e.salary, b.bonus FROM e JOIN b ON e.id = b.id;
CTEs can be named anything. Here, 'e' and 'b' are short names for the CTEs, which are then used in the main query.
Fill all three blanks to define two CTEs and select the combined result.
WITH [1] AS (SELECT id, price FROM products), [2] AS (SELECT product_id, quantity FROM sales) SELECT p.price, s.quantity FROM [3] p JOIN sales s ON p.id = s.product_id;
The first CTE is named 'products', the second 'sales'. The main query selects from 'products' aliased as 'p' and the 'sales' CTE.