473,414 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Duplicate records from one table in a query

I want to run a query that will give me the amounts from two accounts with the same document name. I have a table created for each account (tables are named "171100" & "173100"), and created an Inner join between the tables on the column "Document" to run a query, but I get duplicate entries on the tables' Amount Column. The query looks like this in Datasheet View:

Expand|Select|Wrap|Line Numbers
  1. DOCUMENT 171100.AMOUNT    173100.AMOUNT
  2. 7280         ($324.50)        $89.90
  3. 7280           $89.90         $89.90
  4. 7280          $500.00         $89.90
  5. 7280         ($324.50)       $500.00
  6. 7280           $89.90        $500.00
  7. 7280          $500.00        $500.00
  8. 7280         ($324.50)      ($324.50)
  9. 7280           $89.90       ($324.50)
  10. 7280          $500.00       ($324.50)
But the tables look like this:

Expand|Select|Wrap|Line Numbers
  1. DOCUMENT   AMOUNT
  2. 7280       $89.90      
  3. 7280      $500.00
  4. 7280     ($324.50)
In this case, the numbers are the same in both tables, but that's not always true for all of the docments listed in the tables. Here is the SQL view of my query:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW 
  2.        [171100].DOCUMENT
  3.      , [171100].AMOUNT
  4.      , [173100].AMOUNT
  5. FROM   171100
  6.        INNER JOIN
  7.        173100
  8.   ON  ([171100].DOCUMENT = [173100].DOCUMENT)
  9.  AND  ([171100].DOCUMENT = [173100].DOCUMENT)
Can anyone help? I'm stuck!
Sep 8 '11 #1
7 1795
Rabbit
12,516 Expert Mod 8TB
That output is correct. If you look at the results, there are no duplicate rows. Each instance of the document in the one table will join with every instance of the document in the other table. You've defined no other criteria on which to match on. So those results are correct for what you have defined.
Sep 8 '11 #2
Ultimately, what I want to do is to see all of the amounts in each table that are tied to the particular document, and to have that in one place. Should I be doing this diffently? Sounds like I probably should. What's the best way? Also, ultimately I will have about 30 tables from different accounts, if that matters.
Sep 8 '11 #3
Rabbit
12,516 Expert Mod 8TB
I suspect you need only one, maybe two tables. I don't have any idea what the data is supposed to represent but it's extremely unlikely you're in a position that requires thirty tables. What you probably need is one table with an account field. Rather than thirty different account tables all holding the same data.

As for the query, I have nothing to suggest. From what you have defined, the results of the query is correct. You say that you want to see the amounts for each document number from each table. But if you have three records with the same document number in each table, then you're going to have nine records to show every combination of numbers from each table.

If you look at your table data, record 1 has the same document number as record 2 and record 3. When it tries to match the same data in the other table, record 1 matches to record 1, 2, and 3. Record 2 matches to record 1, 2, and 3. And record 3 matches to record 1, 2, and 3.And that's because you're matching only on document number. It would help to post the results you're after.
Sep 8 '11 #4
NeoPa
32,556 Expert Mod 16PB
It seems like you've added the DISTINCTROW predicate to the SELECT clause in the vain hope of getting rid of some of what you term duplicates in your output. That is not going to work as there is none. You've also added the same WHERE specification in twice by the way. That won't cause any problems other than naff code mind you, and possibly some confusion on the part of anyone trying to decipher it.

Your fundamental problem is to define how you want your records from the two tables to match. At the moment you only specify that they match on [DOCUMENT]. As there are multiple records in each table for the same value though, each will be paired with each of those from the other table, to produce a mini-cartesian product, which is exactly what you're seeing.

As Rabbit says, your results are exactly what would be expected from the situation you describe. You need to consider what it is that causes only one record of each table to pair with only one of the other. When you know that you can include it it your code and get the results you're looking for.
Sep 8 '11 #5
NeoPa
32,556 Expert Mod 16PB
I cross-posted with you guys, but I would echo what Rabbit says about the number of tables. Tables are not supposed to be created for different sets of data, but only for different designs of data. Keep it all in the one table and include an [Account] field.
Sep 8 '11 #6
Ah hah! When you guys told me my query was doing what I had told it to, you knocked a wall out of my head! I have only been using Access for 4 months, & I think I get a bit "Query-Happy". After reading the responses, I realized that I needed to import all 30 of my spreadsheets (the 30 tables) into one table using the "append" option while importing, and then do a query one the one table to sort the documents to group them together, and then I used the "Totals" function to sum the amount. Worked like a charm! Thanks for your advice; you showed me that sometimes I need to think more about tables, rather than running straight to a query!
Sep 9 '11 #7
NeoPa
32,556 Expert Mod 16PB
How pleasant to hear that. Not only is your problem solved, but it was solved by you after something we commented on triggered your new thought processes. the best of all possible outcomes from our point of view. Well done :-)
Sep 9 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
2
by: Ross | last post by:
i have less hair now than i used to...i have a database with many duplicate records in it with only one exception, there is one field with the date it was put in the database and that is different....
1
by: John M | last post by:
Hi, I have two incomplete lists of staff which combined create a full list of staff with duplicates. I wish to create a full list with no duplicates. Each member of staff has and obviously a...
1
by: JG | last post by:
I have an Access 2000 database with a query in it that is pulling data from a table that has duplicate records in it. It is doubling my currency out put. To get rid of the duplicate records in the...
2
by: Allen Anderson | last post by:
Hi, I'm trying to design contact (names and addresses) tables in an Access database. Some of the contacts represent vendors, some are board members of the organization, some are donors, some...
2
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT...
1
by: PerumalSamy | last post by:
Hi I am having table with more 13 lakhs records. I am having duplicate records in it. i need to remove that. I wrote the following query SELECT *
2
Zwoker
by: Zwoker | last post by:
Greetings everyone, I have a problem that I hope has a simple solution. I am using MS Access 2003. I have a table that is a list of financial transactions. I am using a make table query over...
1
by: colin-whitehead | last post by:
I have 2 tables tblReports primary key UPN, plus numeric fields Effort, Attain, etc tblComments numeric primary key ID & textfield Text In the Query I select each record from tblReports...
1
by: billesque | last post by:
Hello! I was wondering if it's possible to take a table in Microsoft Access that contains duplicate records (though not exactly identical) and create queries for use in a form. The form, currently...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.