query returning duplicate rows (1 Viewer)

ijaz196

Registered User.
Local time
Today, 18:51
Joined
Dec 29, 2017
Messages
22
I have three tables named Teacher Attendance, Teacher, Teacher Fine

Teacher Attendance table contains the following fields :
Teacher ID
Attendance Date
Status
School Timing
Arrival Time
Late Time Duration
Remarks

Teacher table contains the following fields :
Teacher ID
Teacher Name
Qualification
Class Assigned
Mobile No
Remarks
Inactive

Teacher Fine Table contains the following fields :
Teacher ID
Date
Absent
Late
Inactive

Now I create a Query with Table Teacher and Table Teacher Fine name Query 44 with contains the following fields:
Teacher ID
Teacher Name
Date
Absent
Late

This query works fine

When I Join this Query 44 with Teacher Attendance (only one field from teacher attendance named "Late Time Duration". It returns the duplicate record with the same data

The query expression is as under

SELECT Query44.[Teacher ID], Query44.[T Att ID], Query44.[Teacher Name], Query44.Date, Query44.Absent, Query44.Late, [Teacher Attend].[Late Time Duration], Month([Date]) AS Expr1
FROM Query44, [Teacher Attend]
WHERE (((Month([Date]))=Month(Now())-1));

Anyone help me why the second query returning in duplicate
I will be grateful for this kindness.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:51
Joined
Oct 29, 2018
Messages
21,449
Hi. Your SQL statement indicates a cartesian product (no join) and your WHERE clause is probably not filtering the duplicates out.
 

ijaz196

Registered User.
Local time
Today, 18:51
Joined
Dec 29, 2017
Messages
22
Mr theDBguy

When I join the both (Querry 44 and table Teacher Fine (with Teacher ID))
the query produced the same result

The query expression is as under

SELECT Query44.[Teacher ID], Query44.[T Att ID], Query44.[Teacher Name], Query44.Date, Query44.Absent, Query44.Late, [Teacher Attend].[Late Time Duration], Month([Date]) AS Expr1
FROM Query44 INNER JOIN [Teacher Attend] ON Query44.[Teacher ID] = [Teacher Attend].[Teacher ID]
WHERE (((Month([Date]))=Month(Now())-1));
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:51
Joined
Oct 29, 2018
Messages
21,449
Mr theDBguy

When I join the both (Querry 44 and table Teacher Fine (with Teacher ID))
the query produced the same result

The query expression is as under

SELECT Query44.[Teacher ID], Query44.[T Att ID], Query44.[Teacher Name], Query44.Date, Query44.Absent, Query44.Late, [Teacher Attend].[Late Time Duration], Month([Date]) AS Expr1
FROM Query44 INNER JOIN [Teacher Attend] ON Query44.[Teacher ID] = [Teacher Attend].[Teacher ID]
WHERE (((Month([Date]))=Month(Now())-1));
Okay, with an INNER JOIN matching the TeacherID, you would get, in return, as many rows as there are matching values in both tables. For example, let's say in Table1, there are 1 TeacherID with a value of 99, and in Table2, there are 3 TeacherID with the same value of 99, then the result of the query will be 3 rows where TeacherID is 99. Does that seem like the case with your tables?
 

ijaz196

Registered User.
Local time
Today, 18:51
Joined
Dec 29, 2017
Messages
22
Thanks for reply
Mr theDBguy

yes both table has the same number in teacher id field
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:51
Joined
Oct 29, 2018
Messages
21,449
Thanks for reply
Mr theDBguy

yes both table has the same number in teacher id field
And there's more than one? If so, that's where the duplicate is coming from. For example, let's say table1 has TeacherID=1 with say TeacherName=Joe and table2 has TeacherID=1 twice with two different associated remarks like Yes and No. Then your query will return both rows like this:
Code:
TeachID   TeacherName   Remarks
1         Joe           Yes
1         Joe           No
You get two Joe's (duplicates). Make sense?
 

ijaz196

Registered User.
Local time
Today, 18:51
Joined
Dec 29, 2017
Messages
22
Thanks for reply
Mr theDBguy

yes both table has the same number in teacher id field
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:51
Joined
Oct 29, 2018
Messages
21,449
Thanks for reply
Mr theDBguy

yes both table has the same number in teacher id field
Looks like this is a duplicate post. Did you see my reply above?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:51
Joined
May 7, 2009
Messages
19,231
how about if you introduced another join field:

SELECT Query44.[Teacher ID], Query44.[T Att ID], Query44.[Teacher Name], Query44.Date, Query44.Absent, Query44.Late, [Teacher Attend].[Late Time Duration], Month([Date]) AS Expr1
FROM Query44 INNER JOIN [Teacher Attend] ON Query44.[Teacher ID] = [Teacher Attend].[Teacher ID] And Month([Date]) = Month([Teacher Attend].[Attendance Date])
WHERE (((Month([Date]))=Month(Now())-1));
 

ijaz196

Registered User.
Local time
Today, 18:51
Joined
Dec 29, 2017
Messages
22
Thanks a lot, Mr theDBguy
It helps me and solves my problems

Thanks a lot again
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:51
Joined
Oct 29, 2018
Messages
21,449
Thanks a lot, Mr theDBguy
It helps me and solves my problems

Thanks a lot again
Hi. You're welcome. Mr Arnel and I were happy to assist. Good luck with your project.
 

Users who are viewing this thread

Top Bottom