Complete the code to start a CTE block.
WITH [1] AS (SELECT * FROM employees)The WITH keyword starts a Common Table Expression (CTE) block in SQL.
Complete the code to separate two CTEs in one query.
WITH first_cte AS (SELECT id FROM users), [1] AS (SELECT id FROM orders)Each CTE needs a unique name. Here, second_cte names the second CTE.
Fix the error in the CTE syntax by filling the blank.
WITH cte1 AS (SELECT * FROM table1) [1] cte2 AS (SELECT * FROM table2) SELECT * FROM cte1 JOIN cte2 ON cte1.id = cte2.id;Multiple CTEs are separated by commas, not repeated WITH keywords or AND.
Fill both blanks to complete a query with two CTEs and a final SELECT.
WITH [1] AS (SELECT name FROM customers), [2] AS (SELECT order_id FROM orders) SELECT * FROM [1] JOIN [2] ON [1].id = [2].customer_id;
The first CTE is named customers and the second orders. These names match the final SELECT.
Fill all three blanks to create two CTEs and a final SELECT joining them.
WITH [1] AS (SELECT id, name FROM employees), [2] AS (SELECT employee_id, salary FROM salaries) SELECT [3].name, [2].salary FROM [1] JOIN [2] ON [1].id = [2].employee_id;
The first CTE is named employees, the second employees is reused as alias for the first CTE in the SELECT. The second CTE is named employees in the options but the correct answer uses employees and employees consistently.