0
0
PostgreSQLquery~10 mins

Multiple CTEs in one query in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a CTE block.

PostgreSQL
WITH [1] AS (SELECT * FROM employees)
Drag options to blanks, or click blank then click option'
AWITH
BSELECT
CFROM
DJOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using SELECT instead of WITH to start a CTE.
Confusing FROM with the CTE start keyword.
2fill in blank
medium

Complete the code to separate two CTEs in one query.

PostgreSQL
WITH first_cte AS (SELECT id FROM users), [1] AS (SELECT id FROM orders)
Drag options to blanks, or click blank then click option'
AJOIN
BSELECT
Csecond_cte
DFROM
Attempts:
3 left
💡 Hint
Common Mistakes
Using SQL keywords like SELECT or JOIN as CTE names.
Leaving the blank empty.
3fill in blank
hard

Fix the error in the CTE syntax by filling the blank.

PostgreSQL
WITH cte1 AS (SELECT * FROM table1) [1] cte2 AS (SELECT * FROM table2) SELECT * FROM cte1 JOIN cte2 ON cte1.id = cte2.id;
Drag options to blanks, or click blank then click option'
A,
BWITH
CAND
DWHERE
Attempts:
3 left
💡 Hint
Common Mistakes
Repeating WITH keyword for each CTE.
Using AND or WHERE instead of comma.
4fill in blank
hard

Fill both blanks to complete a query with two CTEs and a final SELECT.

PostgreSQL
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;
Drag options to blanks, or click blank then click option'
Acust
Borders
Ccustomers
Dsales
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent names between CTEs and final SELECT.
Using unrelated names that don't match the tables.
5fill in blank
hard

Fill all three blanks to create two CTEs and a final SELECT joining them.

PostgreSQL
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;
Drag options to blanks, or click blank then click option'
Aemps
Bemployees
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in CTEs and SELECT.
Using aliases that don't match CTE names.