Exercises
Q1
Q1. What does the SQL clause
LIMIT do?
Q2
What is the purpose of
SELECT DISTINCT?
Q3
What does the SQL
CASE WHEN structure allow you to do?
Q4
Which statement about
HAVING is correct?
Q5
Which join returns only rows that appear in both tables?
Q6
Why is the following SQL query invalid?
SELECT Education, AVG(Age) FROM nhanes GROUP BY Education WHERE Age > 30;
Q7
Which statement correctly explains why the query
SELECT DISTINCT Age, AVG(Age) FROM nhanes; is invalid?
Q8
Why is the following query invalid?
SELECT * FROM nhanes_demographics NATURAL JOIN nhanes_health ON nhanes_demographics.SEQN = nhanes_health.SEQN;
Q9
A student claims this query is invalid:
SELECT Education, AVG(Age) AS avg_age
FROM nhanes
GROUP BY Education
ORDER BY avg_age DESC;
Q10
Why is the following query invalid?
SELECT SEQN, Age FROM nhanes_set1
UNION
SELECT SEQN FROM nhanes_set2;
Q11
Why is this query invalid?
SELECT * FROM nhanes WHERE Ethnicity LIKE %Hispanic%;
Q12
Why is this query invalid?
SELECT Education, Age, AVG(Triglyceride) FROM nhanes GROUP BY Education;