473,396 Members | 1,775 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,396 software developers and data experts.

Getting "duplicate" records in query

Basically (and I'm sure i'm not doing this the "right way") I have a user field that the person who created the record is supposed to select their name from. It is linked to a Users table. I have a query that pulls the records created in the last 7 days, I then have a report that lists those records, sorted and grouped by user and then day.

Here is my SQL for my Query:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Job Bids].[Job Site Name], 
  2.     [Job Bids].[Date Applied], 
  3.     [Job Bids].[Date Posted], 
  4.     [Job Bids].[Position Name], 
  5.     [Job Bids].[Client Name], 
  6.     [Job Bids].Country, 
  7.     [Job Bids].[Bid Type], 
  8.     [Job Bids].[Bid (Gross)], 
  9.     [Job Bids].[Bid (Net)], 
  10.     [Job Bids].URL, 
  11.     [Job Bids].[Post ID], 
  12.     [Job Bids].Email, 
  13.     [Job Bids].Skype, 
  14.     [Job Bids].Invited, 
  15.     [Job Bids].[Client ID], 
  16.     [Job Bids].[Bid (Net)], 
  17.     [Job Bids].[Bid (Gross)], 
  18.     [Job Bids].[Job Description], 
  19.     [Job Bids].[Date Applied], 
  20.     DateDiff("w",[Date Posted],Now()) 
  21.         AS Elapsed, 
  22.     Users.[First Name], 
  23.     [Job Bids].Bidder
  24. FROM [Job Bids], Users
  25. WHERE (((DateDiff("w",[Date Posted],Now()))<7));
I can post the database, but I would need to create a few fake records instead of the real data. What happens, is that each record is shown, BUT it is duplicated with one for each user (so i'm being added to the 2nd record for example, even though I should not be). The Report is just showing two records under the actual user.

Thanks,
Chris
Mar 15 '13 #1
8 1790
Rabbit
12,516 Expert Mod 8TB
That's because you haven't told SQL how to join the two tables. You need tell it that this field in this table needs to equal this other field in this other table.
Mar 15 '13 #2
Where do I do that? I tried to do that in the query, but then I would only get a few records instead of the 20+ I should be. Here is my Relationship report: https://www.dropbox.com/s/dlcfxaebk1hf5u7/Report1.pdf
Mar 15 '13 #3
Rabbit
12,516 Expert Mod 8TB
Please attach the file to the thread itself. Our firewall blocks outside file services.
Mar 15 '13 #4
zmbd
5,501 Expert Mod 4TB
From your posted SQL, there are no obvious relationship(s) between table [Job Bids] and table [Users]. So the query as written will take the cross product between the two table. The relationship is what you need to establish... and actually you may not even need the [users] table unless you need that name field for something.

What you need to do is open the Query in design mode.
I'm sure what you will see are just the two tables in the top portion, no lines between them, and your fields in the grid below.

Now take a look at the two tables... what field(s) are related between the two?

I would suspect something along the lines of:
[Job Bids].[Client ID] and [user].[id]
or
[Job Bids].[Client Name] and [Users].[First Name]

Left Click Drag on the field in [Job Bids] over to the field related field in [Users]. FYI: If you now click on the new line, and right click ON THE LINE, show properties, you will see the dialog box describing the relationship, for now you shouldn't need to adjust anything. Now run your query.... the results shouldn't be duplicated...

Next you really need to take a look at your query design, you have no filter on the user name

Where I think you intended to filter on the user name? If so, then you'll need to do some other tweaks to your query. Using parameters with queries and reports

Leading me to the next, your report... if you're only showing the records from the selected user, then you should not need a grouping on the user name.

You might want to take a look at: 169. Example Filtering on a Form. It's not exactly what you're doing with the report; however, it should lead you some different solutions and is along the same lines as the article I linked you to above.


>OK< It's Saturday here and I need to go help a close friend move a dryer (well two - old and new) into the basement.

Good luck.
Mar 16 '13 #5
I added a ZIP of the two files to this thread.
Attached Files
File Type: zip dbhelp.zip (579.7 KB, 94 views)
Mar 19 '13 #6
zmbd
5,501 Expert Mod 4TB
witeshadow:
Sorry, most of us will not open a non-requested attachment from a relatively new member.
This has absolutely nothing to do with who you are... more like that most of us are at work and there are very strict requirements about downloads.
Very good people are often infected with malware and have no idea... in fact that happened to my Mom and she is fairly tech savvy!

Instead, you need to try an clearly state what is happening be exact with the error titles, numbers, and messages (really, be very literal with the errors) and how this differs from what your goal is.
Mar 19 '13 #7
I totally understand. I just am afraid that there are more details than I know to describe.

I've tried going into relationships and adding a relationship between Bidder in "Job Bids" to ID in Users, but I either get no results in my query, or the wrong results.

@zmbd
Mar 19 '13 #8
zmbd
5,501 Expert Mod 4TB
You do not need to go into the table relationships

What you need to do is open the Query in design mode.
I'm sure what you will see are just the two tables in the top portion, no lines between them, and your fields in the grid below.
> Index of pages on Queries

> Microsoft Access for Beginners— Part III: Writing the Queries

This is for Office 2007; however, a good deal will transfer to 2010:
Access 2007 training courses
Mar 19 '13 #9

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

Similar topics

2
by: Jason | last post by:
I have a table of 650,000 records associated to contracts. Some of the contracts have multiple records but each contract only has one Active Record (there might be several inactive records). ...
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...
2
by: P of Dhump | last post by:
Hi, I am getting some data from a .csv file through an aspx page. The total no of records are 744 while i'm getting 1500. I couldn't really figure it out. I'll write the code below. Dim...
1
by: julian_m | last post by:
I'm working with mysql without referential itegrity. Let me make some small example: tableA +-----------+---------------+ | id_1 | data_1 | +-----------+---------------+ | 1 ...
2
by: Dave | last post by:
I'm in need of a little sql help. How do i get a list of ids from one table that do not have the same ids in another table? I hope that makes sense.
11
by: cgrider | last post by:
I have a query that checks for duplicate records on 2 fields. the issue I am having is that the data unfortunately is case sensitive. So M != m but the query is case insensitive. Is there a way to...
4
by: MLH | last post by:
The SQL string returns 4 records if pasted into a QBE grid and run manually. But in this DAO setting, I can't seem to get it to retrun any records. When line #340 executes, error tells me No...
1
by: yfangl09 | last post by:
I have one query with a list of people and required courses they have to take and another with the same people and courses they have already taken. How do I generate a query with required courses...
0
Telinstryata
by: Telinstryata | last post by:
I have 3 tables for visits. "Visits" holds the visit information, "ReferredBy" holds the different types of referred-by info, and VisitRefByMap maps the two together in a many-to-many relationship. ...
1
anurag275125
by: anurag275125 | last post by:
Hello.. I'm facing problem with a simple select query. this my table structure. Name Null? Type USER_ID NOT NULL VARCHAR2(10) USER_NAME NOT NULL...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.