Skip to content
Advertisement

Pulling different rows based on age in select query

Context

I am using Oracle SQL and have data that looks like this. People are asked every year what their favorite movie is and that may update from year to year.

Problem

I want to write a query so that:

So for Peter and Bob, the desired outcome would look like:

Current code

My current query looks like this:

Advertisement

Answer

One method uses a correlated subquery:

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