Question bank

Pick an answer to see if you're right — with an explanation.

SQL / MySQLEasy
Which clause filters groups after aggregation?
aHAVING
bWHERE
cGROUP BY
dORDER BY
SQL / MySQLEasy
Which keyword starts a Common Table Expression?
aWITH
bUSING
cDEFINE
dAS
SQL / MySQLEasy
Which JOIN returns all rows from the left table?
aINNER JOIN
bCROSS JOIN
cLEFT JOIN
dRIGHT JOIN
SQL / MySQLEasy
Which statement permanently saves the changes made in a transaction?
aSAVE
bROLLBACK
cCOMMIT
dEND
SQL / MySQLEasy
What does `COUNT(*)` count?
aNon-null values
bDistinct values
cColumns
dAll rows
SQL / MySQLEasy
Which window function gives the value from the previous row?
aLEAD
bFIRST_VALUE
cPREV
dLAG
SQL / MySQLEasy
Which keyword removes duplicate rows?
aUNIQUE
bDISTINCT
cDIFFERENT
dSINGLE
SQL / MySQLEasy
In `EXPLAIN` output, what does `type = ALL` indicate?
aAll indexes were used
bA full table scan
cThe query returns all columns
dThe result is cached
SQL / MySQLMedium
Which is best for storing money in MySQL?
aDECIMAL
bFLOAT
cDOUBLE
dVARCHAR
SQL / MySQLMedium
Scores are 90, 80, 80, 70. What `DENSE_RANK()` (ORDER BY score DESC) does 70 get?
a3
b4
c2
d1
SQL / MySQLMedium
What does this return?
SELECT COALESCE(NULL, 0, 5);
aNULL
b5
cError
d0
SQL / MySQLMedium
Why can this query return zero rows even though some customers never ordered?
SELECT name FROM customers
WHERE id NOT IN (SELECT customer_id FROM orders);
aNOT IN only works with numbers
bThe subquery must use DISTINCT
cIf `orders.customer_id` contains a NULL, NOT IN evaluates to unknown for every row
dSubqueries cannot be used in WHERE
SQL / MySQLMedium
What does this query return?
SELECT name FROM staff
ORDER BY salary DESC
LIMIT 3 OFFSET 2;
aThe three lowest salaries
bThe 3rd, 4th and 5th highest-paid staff
cThe three highest-paid staff
dThree rows in random order
SQL / MySQLMedium
Which index can MySQL use for `WHERE status = 'PAID'` alone?
a(customer_id, status)
b(created_at, status)
c(customer_id, created_at, status)
d(status, created_at)
SQL / MySQLMedium
In MySQL 8, how does `TRUNCATE TABLE orders` differ from `DELETE FROM orders`?
aTRUNCATE only removes rows added today
bTRUNCATE keeps the rows but hides them
cTRUNCATE drops and recreates the table, resets AUTO_INCREMENT and cannot be rolled back
dThere is no difference