SQL Quiz

Questions: 16 · 10 minutes
1. Two compatible SELECT queries return email addresses. Which operator combines their results while removing duplicate rows?
JOIN
UNION
UNION ALL
INTERSECT
2. You need every customer, any matching orders, and no unmatched order-only rows. With customers on the left, which join fits?
CROSS JOIN
INNER JOIN
FULL OUTER JOIN
LEFT JOIN
3. During a transaction, an account is debited, but an error occurs before the matching credit and before commit. Which command should cancel the transaction's changes?
COMMIT
SAVEPOINT
ROLLBACK
GRANT
4. Which query returns employees whose salary is greater than the average salary across all employees?
SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
SELECT * FROM employees WHERE salary = (SELECT MAX(salary) FROM employees);
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id;
SELECT * FROM employees WHERE salary > ALL (SELECT salary FROM employees);
5. A query must include customers who are active and whose country is either the US or Canada. Which filter expresses that requirement correctly?
Require active US customers, but include Canadian customers regardless of status
Require active status together with a parenthesized choice between US and Canada
Require each customer to have both US and Canada as the country value
Include anyone who is active, plus anyone located in either listed country
6. Which query returns only the name and email columns from the customers table?
FROM customers SELECT name, email;
SELECT * FROM customers;
SELECT name AND email FROM customers;
SELECT name, email FROM customers;
7. Which clause limits individual rows before GROUP BY creates groups?
HAVING
ORDER BY
WHERE
DISTINCT
8. What is the main role of a foreign key?
To make every value in its column unique
To replace the need for joins
To encrypt values shared between tables
To reference a candidate key in another or the same table and support referential integrity
9. Which expression calculates a running total of amount in date order while retaining each original row?
SUM(amount) GROUP BY order_date
SUM(amount) OVER ()
SUM(amount) OVER (ORDER BY order_date)
LAG(amount) OVER (ORDER BY order_date)
10. Which query correctly counts the number of orders for each customer?
SELECT DISTINCT customer_id, COUNT(*) FROM orders;
SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id;
SELECT customer_id, COUNT(*) FROM orders ORDER BY customer_id;
SELECT customer_id FROM orders HAVING COUNT(*);
11. A table has eight rows, and discount_code is NULL in three of them. What does COUNT(discount_code) return?
5
3
8
0
12. An application must look up a user by a value entered into a form. Which approach most directly reduces SQL injection risk?
Concatenate the value into the SQL string after removing spaces
Hide the SQL statement from the application's users
Escape only quotation marks and build the query manually
Use a parameterized query and bind the entered value as a parameter
13. A grouped query should return only departments with more than 10 employees. Which condition belongs after GROUP BY?
WHERE COUNT(*) > 10
HAVING COUNT(*) > 10
ORDER BY COUNT(*) > 10
DISTINCT COUNT(*) > 10
14. A report should return only records where middle_name has no stored value. Which predicate correctly checks for SQL NULL?
middle_name IS NULL
middle_name equals the text literal 'NULL'
middle_name = NULL
NULLIF(middle_name, '')
15. What is the effect of running UPDATE products SET price = price * 1.10; without a WHERE clause?
Only products with a NULL price are updated
The products are permanently sorted by price
The update is applied to every row in products
A new price column is created
16. What is the primary purpose of a primary key?
To uniquely identify each row in a table
To automatically sort every query result
To store references to rows in another table
To allow duplicate identifiers while improving search speed
Popular tests
Narcissistic Personality Inventory (NPI)
This self-report measure is used to assess narcissism as a personality trai…
Start Test
Yale-Brown Obsessive Compulsive Scale (Y-BOCS)
This measure is used to rapidly quantify the current severity of obsessive…
Start Test
CRAFFT Screening Test (CRAFFT 2.1)
This brief screening measure is designed to identify potential alcohol and…
Start Test
Patient Health Questionnaire-9 (PHQ-9)
This measure is commonly used to quickly screen for the presence and severi…
Start Test
Maslach Burnout Inventory (MBI)
This self-report measure is used to assess occupational burnout symptoms in…
Start Test
Adolescent Anxiety Questionnaire
This measure is designed to support a brief appraisal of anxiety symptoms a…
Start Test
Emotional Creativity Inventory (ECI)
This self-report measure assesses individual differences in the originality…
Start Test
Horne–Ostberg Morningness–Eveningness Questionnaire (MEQ)
Circadian preferences influence typical patterns of alertness and sleep tim…
Start Test
Ambivalent Sexism Inventory (ASI)
This measure is designed to assess attitudes toward women, including both o…
Start Test
Internalized Misogyny Scale (IMS)
This measure is designed to assess internalized negative beliefs and stereo…
Start Test
Perceived Stress Scale (PSS-10)
This self-report measure assesses the degree to which individuals appraise…
Start Test
Impulsive Behavior Scale (SUPPS-P)
Impulsivity is a multidimensional construct that is often assessed with bri…
Start Test
Clinical Institute Withdrawal Assessment for Alcohol, Revised (CIWA-Ar)
This rating scale is used to rapidly assess the severity of alcohol withdra…
Start Test
Positive and Negative Affect Schedule (PANAS)
This measure provides a brief self-report assessment of current or typical…
Start Test
Light Triad Scale (LTS)
This self-report measure assesses prosocial personality tendencies and orie…
Start Test
Suicidal Ideation Scale
In clinical settings, the Suicidal Ideation Scale is used to structure an i…
Start Test
Body Dysmorphic Disorder Scale (BDD-D)
This brief self-report measure is designed to screen for and quantify distr…
Start Test
Beck Anxiety Inventory (BAI)
This measure is a brief self-report inventory used to screen for anxiety sy…
Start Test
Differential Test of Perfectionism
This instrument is used to screen for perfectionism-related attitudes and t…
Start Test
Locus of Control Scale
This measure assesses generalized expectancies regarding the degree to whic…
Start Test
New Apathy Scale
This brief self-report measure is used to screen for apathy-related symptom…
Start Test
Perth Alexithymia Questionnaire (PAQ)
This measure assesses individual differences in alexithymia, including diff…
Start Test
Social Intelligence Scale
This brief self-report measure is designed to support rapid screening of in…
Start Test
Fear Test
This measure is designed to evaluate individual differences in fear-related…
Start Test
Neuroticism Level Scale
The measure is intended for brief screening of an individual’s propensity t…
Start Test
Aggressiveness Indicators Screening Questionnaire
This screening tool is designed to quickly identify behavioral indicators a…
Start Test