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

Eliminating duplicate results in a query

7
Hi everyone,

I have created an MS Access (using 2010) database to manage clients and assignments. The current database setup has a junction table to keep a track of the clients to assignments relationship, and it is a many-to-many relationship, since one client can have several assignments, and an assignment could potentially have more than one client.

Now, I would like for the user to be able to edit the client-assignment relationship in case a mistake is made during the initial data entry, or a change is required. As such, in order to be able to edit said relationship, the user must be able to see a list of clients who can potentially be associated with a particular assignment in question.

I am thus trying to run a query which will display all clients NOT currently associated with the specific assignment OR who have been removed from the assignment (I have setup the junction table to incorporate a toggle allowing the user to turn off the relationship, thus making it seem the client is no longer associated with said assignment, and avoiding deleted records). My currently query setup is as follows:

the clients table (tblClients)
the junction table (tblJnxClientAssign)

I have setup the relationship between the two tables to display all of tblClients and only those in Jnx table that are equal.

I am playing around with the criteria, and so far my results have always had individual clients come up multiple times, and already associated clients showing up due to them being assigned to other assignments. Any suggestions on a solution?


MS Access 2010
My SQL is none existent I am afraid, and little in the way of VBA programming, using Macros in this database so far.
Apr 16 '15 #1

✓ answered by zmbd

I don't normally start out by providing code/sql as I feel that doing this firsthand is the best way to learn. So please stick with me and try to do this yourself... if you get stuck at any-point someone here (or myself) will walk you thru things.

My goal here is just to return the names of the clients. You know the Assignment and the user has selected that information.

So your join table Could have
Expand|Select|Wrap|Line Numbers
  1. [tbl_projects]
  2. [PK][FK_Assignment][FK_Client][Active_Client]
  3. [1 ][1            ][1        ][1] == Assignment 1 Client A
  4. [2 ][1            ][2        ][1] == Assignment 1 Client B
  5. [3 ][1            ][3        ][1] == Assignment 1 Client C
  6. [...]
  7. [6 ][3            ][5        ][1] == Assignment 3 Client E
  8. [7 ][3            ][6        ][1] == Assignment 3 Client F
  9. [8 ][3            ][7        ][0] == Assignment 3 Client G(X)
  10.  
Notice a little change in [Active_Client]... I avoid the Boolean (y/n - t/f) datatype due to some issues I've ran across when migrating Access data to larger databases and because of this article [[ Allen Browne: Why I stopped using Yes/No fields ]] AB has most likely forgotten more than I've learned about databases; thus, I tend to follow his advise. :-)

Basic steps will be these - I'm doing this all by hand with a 2yr at my feet so there maybe a typo or two:

Q1) Query on tbl_projects to return all of your records with active clients
[FK_Assignment]=3; [Active_Client]=1
Return only the [FK_Client]

Q3) You can do this by hand; however, Access's wizard doesn't do too bad of a job and for the non-SQLer may be the way to go...
You need to show your unmatched from [Q1] vs [tbl_clients] create a new query and use the unmatched records wizard.

At this point we should have all of the information needed to start building your list

Q6) You can now take [Q3] against [tbl_client] to retrieve the friendly names by using a join between the [PK] and the [FK] fields and returning the friendly name on only matching records.

8 1526
zmbd
5,501 Expert Mod 4TB
So just make sure I have this correct let me restate the problem:
Assignments 1 thru 10
Clients A() thru G() where A(X) would be assigned but not active.

So:
Assignment 1 could have A, B, C
Assignment 2 could have D, F
Assignment 3 could have E, F, G(x)
Assignment 4 could have A, B, G
etc...

So, if you query on Assignment 3 you would like to have Clients A,B,C,D,G show up in the list of available clients for (re-)association to Assignment 3.

Is this correct so far?
Apr 16 '15 #2
nushi
7
Hi zmbd,

What you described is exactly correct , and that is exactly the result I would want to get when querying on Assignment 3.
Apr 17 '15 #3
zmbd
5,501 Expert Mod 4TB
I don't normally start out by providing code/sql as I feel that doing this firsthand is the best way to learn. So please stick with me and try to do this yourself... if you get stuck at any-point someone here (or myself) will walk you thru things.

My goal here is just to return the names of the clients. You know the Assignment and the user has selected that information.

So your join table Could have
Expand|Select|Wrap|Line Numbers
  1. [tbl_projects]
  2. [PK][FK_Assignment][FK_Client][Active_Client]
  3. [1 ][1            ][1        ][1] == Assignment 1 Client A
  4. [2 ][1            ][2        ][1] == Assignment 1 Client B
  5. [3 ][1            ][3        ][1] == Assignment 1 Client C
  6. [...]
  7. [6 ][3            ][5        ][1] == Assignment 3 Client E
  8. [7 ][3            ][6        ][1] == Assignment 3 Client F
  9. [8 ][3            ][7        ][0] == Assignment 3 Client G(X)
  10.  
Notice a little change in [Active_Client]... I avoid the Boolean (y/n - t/f) datatype due to some issues I've ran across when migrating Access data to larger databases and because of this article [[ Allen Browne: Why I stopped using Yes/No fields ]] AB has most likely forgotten more than I've learned about databases; thus, I tend to follow his advise. :-)

Basic steps will be these - I'm doing this all by hand with a 2yr at my feet so there maybe a typo or two:

Q1) Query on tbl_projects to return all of your records with active clients
[FK_Assignment]=3; [Active_Client]=1
Return only the [FK_Client]

Q3) You can do this by hand; however, Access's wizard doesn't do too bad of a job and for the non-SQLer may be the way to go...
You need to show your unmatched from [Q1] vs [tbl_clients] create a new query and use the unmatched records wizard.

At this point we should have all of the information needed to start building your list

Q6) You can now take [Q3] against [tbl_client] to retrieve the friendly names by using a join between the [PK] and the [FK] fields and returning the friendly name on only matching records.
Apr 17 '15 #4
nushi
7
I was afraid this would need more than one query! lol

Ok, so I have gotten all the way to Q3, and it seems to be working perfectly already! :D The query returns the full list of non actively associated clients, and each client showing up only once. I am manipulating the dummy data to for testing, but seems to be working thus far. Now I can just add the friendly names (easy) and then work out the next steps of actually writing new selections (but thats a different issue all together and I think I can handle it).
Apr 18 '15 #5
zmbd
5,501 Expert Mod 4TB
Friendly names... Q3 against tbl_clients:
Q6: +Join on [tbl_clients]![PK]>[Q3]![FK_clients]
+returning for example [tbl_clients]![Client_FirstName] (...) on matching records. [went back to my second post and labeled this as Q6 :) ]

If you want the assignment name next to each client name
Q7: add tbl_assignments, add Q6
no join
Return fields with the names
Set conditional on tbl_assignments [PK]= for the assignment number of interest

Yes, you most likely can combine all of these queries into one grand SQL statement and there are occasions where I do so; however, I tend to break my queries down into small bites when developing as it makes it easier to troubleshoot - then, often, I just don't go back and combine them into one I am a Chemist not DB-programmer so the priority just isn't there :D

-z
Apr 18 '15 #6
nushi
7
Hrmmm... I am still confused, sorry for being so slow!

As I see it, Q3 is all records in [tbl_Clients] that are NOT in Q1, with Q1 being all actively assigned clients to [FK_Assignment]=X. This by definition will already include any clients assigned to [FK_Assignment]=X that have been deemed inactive, which is the list that I want. Thus if tbl_Clients has 30 records, and 5 are assigned to FK_Assignment=3. Of the 5, 2 are inactive, 3 are active. Q1 will return the 3 active. Q5 will then return everything from tbl_Client that is NOT in Q1, which will be 27 records (30 minus the 3 active clients).

Maybe what I did in Q3 was not exactly as per your instructions (which I may have misunderstood). Thus I am, accidentally, skipping Q2 and Q5 and still reaching the same result?

either way, I am getting the result I need, and it seems to be working fine! So thank you so much for your time and help! :D
Apr 19 '15 #7
zmbd
5,501 Expert Mod 4TB
ahh... nushi... I think you are correct here.
:blush:

My only excuses are doing this in my head with a two year old at my feet (well, and the twins too - two high energy boys and my youngest daughter who isn't too far behind them on the energy chart housebound for winter and now spring rains - just a little bit of cabin-fever starting to set-in ! :D )

Yep, Q1 pulled against tbl_clients will pull all of the unassigned and the inactive clients. I'll edit my post so as not to confuse later readers. Usually I run a test database before posting answers!

Best of Luck with your project!
-z
Apr 19 '15 #8
nushi
7
Hahaha it is quite alright zmbd, I am just grateful for the help and the 2 query solution is working so far so good. Now on to my next step.

Thanks again for your time and effort, and good luck with the cabin-fever (I do not envy you! lol)!
Apr 19 '15 #9

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

Similar topics

6
by: Matt B | last post by:
Can somebody help me with this please... I have an xml file along the lines of <results> <result status="Pass"> <person name="Fred"/> <subject name="English" /> </result> <result...
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...
4
by: aamircheema | last post by:
Hi, Say I have a table Job with columns name, date, salary . I want to get the name ,date and salary for the date when that person earned maximum salary. I am using something like SELECT...
1
by: JC | last post by:
Hello, I am trying to change a select, find duplicates, query into a delete query. I want to get rid of the records in the main table "tblHurnsHistory." I changed the Find Duplicates query to...
5
jamesd0142
by: jamesd0142 | last post by:
My manager and I where looking at some complex code to eliminate duplicate records in a database table. then it hit me how its done easily... so i thought i'd share it... In English:...
2
by: pidoling | last post by:
I am working on this query that includes two tables. the first table(withpay) has detail information and the second table (txdata) has the summary of data. withpay (join) ...
5
by: LH731 | last post by:
I am pretty new at Access, but below is the code for my query. I am trying to obtain the most current meeting/contact date and its details for each meeting/contact. A few of the companies show up...
2
by: gbrocato | last post by:
Looking to find a way to only pull the latest results if there happens to be duplicate. When searching a container in our system, if it doesn't have a dupe I want it to pull that information. But...
75
by: DK88 | last post by:
I have spent numerous hours now searching for a solution to this problem, but everything I have tried just hasn't work. I will try to be as detailed as possible to help explain the problem. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.