0
0
SQLquery~10 mins

Set operations with ORDER BY in SQL - Interactive Code Practice

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

Complete the code to combine two tables and order the results by the column 'name'.

SQL
SELECT name FROM employees UNION SELECT name FROM managers ORDER BY [1];
Drag options to blanks, or click blank then click option'
Aname
Bsalary
Cid
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column not selected in the query for ORDER BY.
Forgetting to specify the column in ORDER BY.
2fill in blank
medium

Complete the code to get all unique product IDs from two tables and order them in descending order.

SQL
SELECT product_id FROM sales UNION SELECT product_id FROM returns ORDER BY [1] DESC;
Drag options to blanks, or click blank then click option'
Aquantity
Bcustomer_id
Cdate
Dproduct_id
Attempts:
3 left
💡 Hint
Common Mistakes
Ordering by a column not in the SELECT list.
Using ASC instead of DESC when descending order is required.
3fill in blank
hard

Fix the error in the query by completing the ORDER BY clause to sort by 'score'.

SQL
SELECT user_id, score FROM game1 INTERSECT SELECT user_id, score FROM game2 ORDER BY [1];
Drag options to blanks, or click blank then click option'
Alevel
Buser_id
Cscore
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Ordering by a column not selected in the query.
Using a column from only one SELECT statement.
4fill in blank
hard

Fill both blanks to combine two tables with UNION ALL and order by 'date' ascending and 'amount' descending.

SQL
SELECT date, amount FROM payments UNION ALL SELECT date, amount FROM refunds ORDER BY [1] ASC, [2] DESC;
Drag options to blanks, or click blank then click option'
Adate
Bamount
Ccustomer_id
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of columns in ORDER BY.
Using columns not selected in the query.
5fill in blank
hard

Fill all three blanks to combine two tables with EXCEPT and order by 'category' ascending, 'price' ascending, and 'stock' descending.

SQL
SELECT category, price, stock FROM inventory1 EXCEPT SELECT category, price, stock FROM inventory2 ORDER BY [1] ASC, [2] ASC, [3] DESC;
Drag options to blanks, or click blank then click option'
Acategory
Bprice
Cstock
Dsupplier
Attempts:
3 left
💡 Hint
Common Mistakes
Using columns not in the SELECT list for ORDER BY.
Incorrect order or direction in ORDER BY clauses.