Libre
been around a little
- Local time
- Today, 11:46
- Joined
- May 3, 2007
- Messages
- 681
Sorry if this is a baby question - I'm largely self-taught and have developed methods to get what I want done. There are a lot of things that I do, though, that may not be the "right" way, the "usual" way, or the most efficient way.
One of those things is how you look up a record in a table.
The situation is the following:
Let's say I have Table A which is a table of ALL products indexed by Part Number, and Table B which is a list of products that have been returned, also indexed by Part Number. I want to determine, for every record in Table A if it has been returned and thus appears in Table B.
What's the best way to do it?
The two ways I can think of are:
1- assign the Part Number that I'm looking for to a variable; loop through every record in Table B and if the record ID matches the variable then I know it's a "hit" and the part number was found;
OR
2- create a single record query that returns only the one record if it finds a match in Table B to the part number I'm looking for from Table A - or no records if it finds no match. It does this by executing a function that is called in the Criteria field in the query builder. The function returns the literal Part Number to the Critera field. Then if I have an empty record set then I know the part number from Table A does not appear in Table B.
I'm not sure if all this is clear. My basic question is:
What's the best/easiest test to see if a record from one table appears in another table?
I don't want to hard code it for that one record, obviously.
I will need to loop through every record in Table A and if it finds a corresponding record in Table B then one thing happens (a flag is set for example that the Part was returned), and if not it will do something else (not set or unset that flag) - so it has to work for any record and all records in Table A.
Sorry if too long winded.
I generally use method 2 above and create single record queries because the loop structure (method 1) is a big pain and I have method 2 down cold - but, it involves creating queries, global variables, and functions - sometimes more than 1 - and I'm not sure that it is the fastest way. If Table A has many records than this step really can slow things down a lot - but so would the loop.
Thanks for any replies.
One of those things is how you look up a record in a table.
The situation is the following:
Let's say I have Table A which is a table of ALL products indexed by Part Number, and Table B which is a list of products that have been returned, also indexed by Part Number. I want to determine, for every record in Table A if it has been returned and thus appears in Table B.
What's the best way to do it?
The two ways I can think of are:
1- assign the Part Number that I'm looking for to a variable; loop through every record in Table B and if the record ID matches the variable then I know it's a "hit" and the part number was found;
OR
2- create a single record query that returns only the one record if it finds a match in Table B to the part number I'm looking for from Table A - or no records if it finds no match. It does this by executing a function that is called in the Criteria field in the query builder. The function returns the literal Part Number to the Critera field. Then if I have an empty record set then I know the part number from Table A does not appear in Table B.
I'm not sure if all this is clear. My basic question is:
What's the best/easiest test to see if a record from one table appears in another table?
I don't want to hard code it for that one record, obviously.
I will need to loop through every record in Table A and if it finds a corresponding record in Table B then one thing happens (a flag is set for example that the Part was returned), and if not it will do something else (not set or unset that flag) - so it has to work for any record and all records in Table A.
Sorry if too long winded.
I generally use method 2 above and create single record queries because the loop structure (method 1) is a big pain and I have method 2 down cold - but, it involves creating queries, global variables, and functions - sometimes more than 1 - and I'm not sure that it is the fastest way. If Table A has many records than this step really can slow things down a lot - but so would the loop.
Thanks for any replies.
Last edited: