[Solution] Return the second fastest runner
Click here to view the question
Apply a limit and offset with an order by to return the second fastest runner
select name , seconds from runners order by seconds limit 1 offset 1
Concepts Covered: Order by, Limit, Offset
We first need to arrange runners from fastest to slowest. This is done by applying "order by seconds." By default, SQL arranges numerical values from lowest to highest. If we had wanted to arrange numerical values from highest to lowest, we would run "order by second desc"
Then we apply a limit 1 to ensure our output only returns 1 row. If we wanted to return the fastest runner, we would be done! However, we need to apply an offset 1 to have SQL skip the first row and return the second. If we wanted to return the third fastest runner, we would have applied an offset 2. For the fourth fastest runner, we would have applied an offset 3, and so on.