Hopefully you can see from the code what I want to achieve but am currently unsuccesful.
I want to join on to each booking the latest record from from the audit table for that booking, however because the audit table is so big I would like to limit the nested select to only search for the records corresponding to the booking on each join iteration.
Currently though the statement does not recognise b as a table alias.
Code:SELECT * FROM Bookings as b INNER JOIN (SELECT MAX(record_id) as LatestAuditID, bookingnumber FROM audit a WHERE a.bookingnumber=b.booking_number GROUP BY bookingnumber ) AS aud ON aud.bookingnumber = b.booking_number





Reply With Quote