Databases and SQL: Question 9
Syllabus 9.4
Peak Trail Running Club records the results of every timed run in a single database table called RACE_TIME, shown below.
| RunnerID | RunnerName | TrailName | TimeMinutes | Finished |
|---|---|---|---|---|
| RT01 | Jonas Berg | Ridge Loop | 42 | True |
| RT02 | Aisha Rahman | Ridge Loop | 38 | True |
| RT03 | Jonas Berg | Forest Trail | 55 | True |
| RT04 | Priya Shah | Forest Trail | 47 | False |
| RT05 | Aisha Rahman | Forest Trail | 50 | True |
A club member runs this SQL statement:
SELECT MIN(TimeMinutes)
FROM RACE_TIME;
What value does this statement return?
Show worked solution Hide worked solution
Worked solution
Step 1: Look at every value in the TimeMinutes column
SELECT MIN(TimeMinutes) FROM RACE_TIME; has no WHERE clause, so every row in the table is considered: 42, 38, 55, 47 and 50.
Step 2: Find the smallest value
Comparing all five values, 38 (RT02, Aisha Rahman on Ridge Loop) is smaller than every other value in the column.
Step 3: Confirm the match
MIN(TimeMinutes) returns the smallest value found, which is 38. (55 is the largest value, which is what MAX would return; 46.4 is the average of all five values, which is what AVG would return; and 5 is simply the number of records in the table.)
Final answer
The statement returns 38, option A.