Skip to content
Advertisement

Select first and nth order for each client

I’m trying to display first and fifth order_id for each user.

Table looks like this:

I wrote something like this:

But I want to see clients who made their first orders but don’t have fifths. There should be NULL, but I can’t understand how to make it. :c

Advertisement

Answer

Put the where t2.rn = 5 condition into the left join:

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