Select query returning too many records

D

dascooper

I have a select query that doesn't seem to be joining correctly. Table 1
includes the following Fields:

Code
Adjustment
Other

Table 2 includes the following fields
Code Match
Year
Cost

table 1 can match to table 2 multiple times. However, the query is
currently returning matches for every record in both tables (#records T1 *
#records T2). I have joining the tables and applying a filter in the table
where code match = code, but no luck. I have this working in another table,
but cannot seem to resolve the issue with this one. T2 is a query - not sure
if it makes a difference, though - the results from that one are fine.

Table 1 includes multiple matches to Table 2. The way it should work is
that for each record it table 2, it should return anywhere from
 
K

Klatuu

With a question like this it is necessary that you post the SQL of your
query so we can see what you are doing.
Also, based on your description, you are getting the results you should
expect. When you have a situation where there can be multiple matches
between the tables, you can expect to get a record for each possible match.
 
R

Ron2006

This is the table that is probably creating the confusion.

Code
Adjustment
Other

explanation:
If there are 2 records with a code of (say) 123 and 5 records with
code 123 in table 2 then the resulting query will list

record 1 code 123 - table 2 record 1 matchcode 123
record 1 code 123 - table 2 record 2 matchcode 123
record 1 code 123 - table 2 record 3 matchcode 123
record 1 code 123 - table 2 record 4 matchcode 123
record 1 code 123 - table 2 record 5 matchcode 123
record 2 code 123 - table 2 record 1 matchcode 123
record 2 code 123 - table 2 record 2 matchcode 123
record 2 code 123 - table 2 record 3 matchcode 123
record 2 code 123 - table 2 record 4 matchcode 123
record 2 code 123 - table 2 record 5 matchcode 123

In order to have only 5 records to show you will have to use a query
on table 1 that is grouped by code. Then you will need to determine
what to do about the grouping or first or last etc for the other two
fields that are present in table 1 for each now unique code.

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top