Skip to content
Advertisement

Nested queries in SQL

I am trying to combine 2 queries using a nested query. The first one is this:

Which generates the result

So 451 is on Mach1. The tricky part is that for ShortenCode i would like to show the previous Mach that it was on. It would be something like:

How can I subquery to get:

Basily Mach column has Mach1, Mach2 and also Mach4 and Mach5. I’ve tried this but with no success:

If you have any suggestions I would appreciate very much

Advertisement

Answer

I think you can try getting the subquery in the SELECT part like this

although I am guessing that depending on the indexing and the amount of data it could take long to compute.

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