Skip to content
Advertisement

Subquery sorted by another table

This is a follow-up question to Get the following record in query. But the task is a bit more complicated. I tried to modify the SQL query but I was not able to fulfill the task.

If we have two tables, one called Activity and has rows [ActivityCode and StartTime], and the another one called Students has rows [Name and ID] for example:

And now I want to make one SQL Query to display as follow:

I follow the code, credits to Gustav:

I tried to modify the part

Because the whole query is sorted according to the Student ID which is from another table. But some message boxes popped up and I couldn’t solve it. How can I modify it? thank you.

Advertisement

Answer

Consider this SQL:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement