in reply to Merging/Rearranging Tables
To do it in perl, your first idea is on the right track, and is one of the fastest/most efficient ways to do this with a couple minor optimizations:
- Make a single list of all unique ID values from all tables. As already suggested, a hash would be ideal for this, since it will eliminate any duplicates.
- Sort this list and sort all tables by ID.
- Walk the list of unique IDs and grab the matching record (if any) from each table. Since everything's sorted, you can just run a single query against each table and only advance a record when a match is found.
This gives you a total of two queries against each table, one to collect all IDs at the start, then one to grab the data by ID after that list is built.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Merging/Rearranging Tables
by homeveg (Acolyte) on Feb 11, 2007 at 01:21 UTC |