Challenge your understanding of SQL queries with this beginner-friendly quiz focused on common interview topics such as selecting unique values, table joins, and data ordering using a hospital database schema. Strengthen your skills in interpreting table relations, essential SQL functions, and logic relevant to healthcare data scenarios.
Which SQL clause would you use to display unique birth years from a patient table's 'birth_date' column?
Explanation: The DISTINCT keyword removes duplicate values, and applying YEAR() extracts just the year from 'birth_date', so 'SELECT DISTINCT YEAR(birth_date)' returns all unique years. Using GROUP BY without aggregation is less direct and requires extra steps. SELECT UNIQUE is not standard syntax, and the last option doesn't extract or format the year.
If you want to combine data from the patient table and admission table using the patient ID, which SQL operation should you use?
Explanation: JOIN allows you to combine rows from two tables based on related columns, such as patient ID. UNION joins result sets, not rows. GROUP BY is used to aggregate data, and ORDER BY is for sorting, so neither GROUP BY nor ORDER BY can combine rows from separate tables.
How would you sort the unique birth years you retrieved from the patient table in ascending order?
Explanation: ORDER BY is the correct SQL clause for sorting, while ASC specifies ascending order. GROUP BY is used for aggregation, not sorting. 'SORT' is not valid SQL syntax, and 'ORDER ... DESC' sorts in descending order, which is the opposite of ascending.
Which SQL statement returns a list of all different first names from the patient table?
Explanation: 'SELECT DISTINCT first_name' returns only unique first names. 'ALL' does not filter duplicates. GROUP ALL and UNIQUE after column name are not valid SQL syntax and will result in an error.
To display each patient's province name along with their first name, which type of JOIN should you typically use between the patient and province tables?
Explanation: INNER JOIN combines rows with matching province IDs in both tables, effectively giving you patient information and associated province names. CROSS JOIN would produce all possible pairs, FULL JOIN is rarely needed in this context, and SELF JOIN connects a table to itself, which is not relevant here.
Which clause should you add to retrieve all admissions handled by a doctor with the ID of 7?
Explanation: The WHERE clause filters rows based on conditions, such as doctor_id being equal to 7. GROUP BY organizes rows for aggregation, HAVING is used after GROUP BY, and LIMIT controls result count, not row filtering.
What simple SQL function could help detect if multiple patients share the same first name in the patient table?
Explanation: COUNT totals occurrences of a given value, helping identify duplicates when combined with GROUP BY. MAX and MIN find maximum or minimum values, and AVG calculates an average, none of which directly indicate duplicates.
Which symbol allows you to select every column from the patient table without listing each column name?
Explanation: The asterisk (*) is used to select all columns in SQL. The other symbols (#, u0026, !) are not valid and will cause syntax errors if used in this context.
Which SQL function would you use to find the most recent 'birth_date' value in the patient table?
Explanation: MAX returns the largest (most recent, chronologically) date value in a column. MIN provides the earliest date, and SUM and COUNT are for numeric totals and counting rows, not finding maximum values.
To determine how many different doctors have admitted patients, which field should you select with DISTINCT from the admission table?
Explanation: doctor_id identifies which doctors are involved in admissions, so DISTINCT on this field counts unique doctors. admission_id is unique for every admission and patient_id for patients, so those would not show the count of different doctors. province_id relates to location, not admissions by doctor.