|
-
Oct 2nd, 2010, 12:28 AM
#5
Re: Using parent row in subquery where clause
 Originally Posted by FishGuy
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
Since the audit table is big we have to avoid full table scans... what are the available indices on audit table and bookings table? How many rows are in audit table and in bookings table?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|