I have a SQL 2000 DB with and old table and a new table with combined records of over 20,000,000 records. The two tables are exactly the same, but were split due to performance issues. I am not the DB admin, I just need data out of it and have been given DBReader rights on it.
OldTable:
ClientID,
AppID,
ModTime,
Event
NewTable:
ClientID,
AppID,
ModTime,
Event
I need to retrieve the most recent record for each client, appid and event from whichever table has the most recent entry for it. Anyone any ideas about the best method for this? I have tried using a union, but the query takes over two hours to complete. I was thinking of using a join instead, but I’m not sure the best approach.
Thanks!
you will have to use a
UNION, but if the tables are DISTINCT, consider using aUNION ALLwhich will be faster.Also ensure that you have the correct indexes on the tables for this kind of query.