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

Access 2013 query duplicating records

I need to combine that data from 2 seperate queries. Each query is counting, one the number of employees in a department by shift and the other is counting the number of employees that have entered a help idea into the system. The problem I'm experiencing is that when I pull the data from one or both of the queries it is duplicating the records. When I run either of the queries that I'm pulling from they have no duplicates. Here is the sql from the two queries.

Expand|Select|Wrap|Line Numbers
  1. SELECT qDepartments.DeptName, qParticipationShiftCount.Shift, Count(qParticipationShiftCount.EmpID) AS CountOfEmpID1
  2. FROM qDepartments INNER JOIN qParticipationShiftCount ON qDepartments.DeptName = qParticipationShiftCount.DeptName
  3. GROUP BY qDepartments.DeptName, qParticipationShiftCount.Shift
  4. HAVING (((qDepartments.DeptName)<>"Primer Manager" And (qDepartments.DeptName)<>"Centerfire Manager" And (qDepartments.DeptName)<>"Rimfire Manager" And (qDepartments.DeptName)<>"HR"));
  5.  
Expand|Select|Wrap|Line Numbers
  1. SELECT Department.DeptName, dbo_MasterEmployeeList.Shift, Count(dbo_MasterEmployeeList.EmpID) AS CountOfEmpID
  2. FROM (Department INNER JOIN DepNumber ON Department.DeptName = DepNumber.DeptName) INNER JOIN (dbo_MasterEmployeeList INNER JOIN dbo_vSiteAreaDeptDetail ON dbo_MasterEmployeeList.SiteAreaDeptID = dbo_vSiteAreaDeptDetail.SiteAreaDeptID) ON DepNumber.[Dept#] = dbo_MasterEmployeeList.Department
  3. WHERE (((dbo_vSiteAreaDeptDetail.SiteID)=15))
  4. GROUP BY Department.DeptName, dbo_MasterEmployeeList.Shift, dbo_MasterEmployeeList.Status
  5. HAVING (((dbo_MasterEmployeeList.Status)="A"));
  6.  

Here is the code for the query that is pulling the data. The minute I load the 2nd table, even if I do not use any of it's fields it starts causing the query to duplicate repeatedly.

Expand|Select|Wrap|Line Numbers
  1. SELECT qParticipationShift2PlusCount.DeptName, qParticipationShift2PlusCount.Shift, qParticipationShift2PlusCount.CountOfEmpID1
  2. FROM qParticipationShift2PlusCount, qParticipationShiftEECount;
  3.  
Nov 19 '15 #1

✓ answered by jforbes

You'll probably want to use a Union instead of including both tables in the FROM clause.

When you add multiple tables to the FROM clause instead of Joining the additional tables, a row for each combination of rows in the supplied tables is returned. So if you have Ten Rows in qParticipationShift2PlusCount and Four Rows in qParticipationShiftEECount you will get a result set of Forty Rows.

Using a Union is fickle as you need to have the same amount of columns in the two constituting result sets as well as the column names have to match one for one.

2 870
jforbes
1,107 Expert 1GB
You'll probably want to use a Union instead of including both tables in the FROM clause.

When you add multiple tables to the FROM clause instead of Joining the additional tables, a row for each combination of rows in the supplied tables is returned. So if you have Ten Rows in qParticipationShift2PlusCount and Four Rows in qParticipationShiftEECount you will get a result set of Forty Rows.

Using a Union is fickle as you need to have the same amount of columns in the two constituting result sets as well as the column names have to match one for one.
Nov 19 '15 #2
NeoPa
32,556 Expert Mod 16PB
SQL JOINs gives some more info on how best to work with JOINs, as well as a description of the cartesian product result set that you have and JForbes described.
Nov 19 '15 #3

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

Similar topics

0
by: steveradaza | last post by:
Sir,Good Day..I am a newbie here and i am just learning the usage of microsoft access..can you help me solve my problem in making a running balance in a query of microsoft access 2013 of my In and...
3
RockKandee
by: RockKandee | last post by:
I am using the MS Access Calendar in Access 2013, Windows 8. http://bytes.com/topic/access/answers/761255-ms-access-calendarhttp:// Currently I am using 4 calendar forms with the data source...
4
by: nomeepk | last post by:
hi, i am using access 2013, Is there a way i can make this Access Database online, so i can access and use it from anywhere in a Browser? Regards.
5
by: jimatqsi | last post by:
I'm looking for information about compatibility between Access 2013 and Access 2003. I've been approached by a firm that wants to begin upgrading their systems. I want to know if it is reasonable...
0
by: LeoVBNET | last post by:
Hi Because VS 2013 dropped SQL COMPACT databases, I need to convert Access 2013 databases into SQL COMPACT in order to be able to use Linq to SQL in VB 2013. Anybody can help me? Thanks
6
by: GKJR | last post by:
I have been using Access 2013 (in Office 365) with Windows 8.1 for about a month and a half now. I was a little reluctant to switch from 2010 on Windows 7, but I figured I should try stay ahead of...
3
Seth Schrock
by: Seth Schrock | last post by:
I just discovered that Access 2013 puts in a default value of 0 for number fields. This is very annoying when relating fields and you get an error when trying to insert records thinking that I'm...
6
by: msilva100 | last post by:
Hello, I need to have remote access to a MS Access 2013 Database running on a Windows 7 Server. Can someone kindly recommend a remote access tool? Thank you.
7
by: jpreator | last post by:
I have a query that is counting the number of records that fall between two dates as specified in a form using two combo boxes. The query is grouped by two categories, value stream and department. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...

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.