Removing duplicates in MS Access query

Experts:

In the query below, I have a criteria clauses to
(1) exclude terminated employees, pensioners, casuals and interns from a query of non-support employees A or
(2) include Terminated Employees but only if they have associated records in an allocations table B.

But the allocations table (table B) has multiple records per employee so I'm getting duplicates with the expression in the 2nd Where clause: AND ((B.clock_to) Is Not Null))

Suggestions?

SELECT A.Source, A.Status, A.EmployeeName, A.strClock, A.Category, A.Title, A.Program, A.Program2, A.Program3, A.Location, A.RecentHireDate, A.[Band], A.WorkPct, A.Supervisor, A.Supervisor2Name, A.Supervisor3Name, A.FLSA, A.EmpLevel, A.EmpLevelBud, A.HRPartner, A.TerminationDate, A.Budgeted, A.ReasonForVacancy, A.Replacing, A.PostingStatus, A.BusinessFunction

FROM (qAllNonSupport AS A LEFT JOIN tClockAllocations AS B ON A.strClock = B.clock_to) LEFT JOIN tEmpAttributesNonSupport AS C ON A.strClock = C.strClock

WHERE
(((A.Status)<>"Terminated" And (A.Status)<>"No") AND ((A.Category) Not In ("Pension Payroll","Intern","Casual")) AND ((C.SupportEligible)=Yes))

OR (((A.Status)="Terminated" And (A.Status)="No") AND ((B.clock_to) Is Not Null))

OR (((A.strClock)="1539") AND ((C.SupportEligible)=Yes))

ORDER BY A.Source, A.EmployeeName;
TIA
LVL 1
DavisroBudget AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<I thought to take it out of the GUI and into the Sql editor and replace AND ((B.clock_to) Is Not Null)) with a WHERE EXISTS subquery such as AND ((WHERE EXISTS B.clock_to) Is Not Null)) but I don't know how to write it.>>

 You want to avoid sub-queries in Access if you can as they are a real performance drain.

 Instead, either:

1. Use SELECT DISTINCT in your query (Unique Values = True in query properties).

2. Use SELECT DISTINCTROW in your query (Unique Records = True in query properties).

3. Create another query that returns the values you need to check on, use that as a "table" in your main query, and use an OUTER JOIN (returns all records from your main table and only matching records from the joined table - get to it by double clicking on the join line).   Then pull down one field from the join table and use:

 IS NULL

or

NOT IS NULL

 as appropriate so records from the main table are included or excluded.

Jim.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavisroBudget AnalystAuthor Commented:
Query Properties: Unique Values = Yes

As always Jim, you da man! I didn't know which method, Distinct or Distinct Row or subqueries were more preferable than the other.

Thanks a lot!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.