# New to Group - Record Duplicates, not single record shown

**URL:** <https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756>\
**Category:** Toad for Oracle & DevOps Toolkit\
**Created:** [June 23, 2023, 9:14pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756 "2023-06-23T21:14:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brd1107](https://avatars.discourse-cdn.com/v4/letter/b/9f8e36/32.png) [@brd1107](https://forums.toadworld.com/u/brd1107)\
**Post date:** [June 23, 2023, 9:14pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/1 "2023-06-23T21:14:17Z")

</div>

I'm new to the group and the use of Toad so I thank you for your understanding with this question.

I have a query I'm running to provide me the date a record was received for a specific individual. When I run the query, it brings back upwards of 180 records, all with the same information.

I'm not sure if I'm doing the query wrong or too many join commands to get the information needed in a certain format.

Any assistance would be great.

---

<div class="post-metadata">

**Author:** ![JohnDorlon](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/johndorlon/32/9997_2.png) [@JohnDorlon](https://forums.toadworld.com/u/JohnDorlon)\
**Post date:** [June 23, 2023, 9:19pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/2 "2023-06-23T21:19:48Z")

</div>

It sounds like you have what's called a Cartesian Join to me.

That is when you don't join all of the primary key columns of all tables involved in your where clause.

So if table1 has primary key A, B and you want to join it to table2 with primary key A, B,  
...you probably need to do something like:

select T1, T2  
from table1 T1, table2 T2  
where T1.A = T2.A  
and T1.B = T2.B

failure to include all of the key columns in the join can result in "duplicate" rows returned like you describe.

---

<div class="post-metadata">

**Author:** ![brd1107](https://avatars.discourse-cdn.com/v4/letter/b/9f8e36/32.png) [@brd1107](https://forums.toadworld.com/u/brd1107)\
**Post date:** [June 23, 2023, 9:34pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/3 "2023-06-23T21:34:45Z")

</div>

Here is an example of the code, minus a few lines. If I need to provide the whole code, I can, just need to clean it up a little more.

select  
c.Case\_RCVD\_DT,  
c.office\_display,  
f.case\_number,  
f.LAST\_NM||', '||p.FIRST\_NM AS client\_NAME,  
e.case\_STATUS,  
e.Case\_STATUS\_BEGIN\_DT,  
from schema 1.table\_1 c  
left join table 2 f  
on f.table 1 = c.table\_1  
left join schema2.table3 e  
on e.Table3 = f.table4  
Where  
c.claim\_rcvd\_dt \>= '01-Jun-2023'  
and f.case\_status\_begin\_dt \>= '01-June-2023'  
AND e.office\_display = 'Los Angeles Office'

---

<div class="post-metadata">

**Author:** ![JohnDorlon](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/johndorlon/32/9997_2.png) [@JohnDorlon](https://forums.toadworld.com/u/JohnDorlon)\
**Post date:** [June 23, 2023, 9:47pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/4 "2023-06-23T21:47:44Z")

</div>

It's impossible for me to know for sure w/o knowing the primary keys on these tables, but I'm still guessing there is some join info missing somewhere in the ON clause.

It should probably look more like:

left join table 2 f  
on f.primary\_key\_column = c.primary\_key\_column and ...... add other PK columns here if there are more than one.

...for each table.

---

<div class="post-metadata">

**Author:** ![brd1107](https://avatars.discourse-cdn.com/v4/letter/b/9f8e36/32.png) [@brd1107](https://forums.toadworld.com/u/brd1107)\
**Post date:** [June 23, 2023, 9:51pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/5 "2023-06-23T21:51:58Z")

</div>

Understand. I will do a clean up with a few of the table and column names for each I'm joining and send that over.

Thanks again...

---

<div class="post-metadata">

**Author:** ![JohnDorlon](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/johndorlon/32/9997_2.png) [@JohnDorlon](https://forums.toadworld.com/u/JohnDorlon)\
**Post date:** [June 23, 2023, 10:02pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/6 "2023-06-23T22:02:20Z")

</div>

It may be easiest to start with a single table, get the data you want, then join in a 2nd, get the data you want (no duplicate rows, etc), then move on to the 3rd. Do a little at a time.

---

<div class="post-metadata">

**Author:** ![brd1107](https://avatars.discourse-cdn.com/v4/letter/b/9f8e36/32.png) [@brd1107](https://forums.toadworld.com/u/brd1107)\
**Post date:** [June 23, 2023, 11:07pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/7 "2023-06-23T23:07:22Z")

</div>

Hope this helps out.

Schema A  
Table: 1.1  
Column Names:  
Case\_ID  
Office\_ID  
File\_ID  
Last\_Nm  
First\_Nm  
Case\_Status  
Client\_case\_id

Schema B  
Table 2.2  
Column Names:  
Case\_ID  
Employee\_Name  
Employee\_ID  
Case\_Status\_Begin\_Date

Schema B  
Table 3.3  
Column Names:  
Geography\_ID  
Office\_Display  
Region\_Display

Schema C  
Table 4.4 p  
Column Names:  
Client\_ID  
Last\_NM  
First\_NM  
Birthdate  
Gender

Schema C  
Table 5.5  
Column Names:  
Client\_Case\_id  
Services  
Last\_Paid

Select  
q.claim\_rcvd\_dt,  
p.client\_number,  
p.Last\_NM II ‘, ‘ IIp.First\_NM AS Client Full Name  
f.case\_status  
From schema 1.table 1.1 c  
Left join schema b.table\_2.2 f  
Left join schema c.table\_4.4 p  
On p.client\_id = c.client\_case\_id  
Left join schema\_c.table\_5.5 q  
On q.client\_case\_id = c.client\_case\_id q  
Where  
q.claim\_rcvd\_dt \>= '01-Jun-2023'  
and f.case\_status\_begin\_dt \>= '01-June-2023'  
AND e.office\_display = 'Los Angeles'

---

<div class="post-metadata">

**Author:** ![JohnDorlon](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/johndorlon/32/9997_2.png) [@JohnDorlon](https://forums.toadworld.com/u/JohnDorlon)\
**Post date:** [June 26, 2023, 12:21pm UTC](https://forums.toadworld.com/t/new-to-group-record-duplicates-not-single-record-shown/57756/8 "2023-06-26T12:21:08Z")

</div>

I don't see a join between table1.1 and 2.2. Not sure if that's the only problem.

From schema 1.table 1.1 c  
Left join schema b.table\_2.2 f  
**ON C.CASE\_ID = F.CASE\_ID**  
Left join schema c.table\_4.4 p  
On p.client\_id = c.client\_case\_id  
Left join schema\_c.table\_5.5 q  
On q.client\_case\_id = c.client\_case\_id q

If that's not it, try rebuilding your query from scratch. Start with only one table. Join in one table at a time. Test it, make sure the data looks right, then add in another table, and continue adding one table at a time and making the joins right as you go. Using that technique, you should be able to spot where it's going wrong.

Also, are you sure you want Left Joins and not inner joins? Left joins do tend to return more rows. You can read the difference between them here [SQL LEFT JOIN](https://www.w3schools.com/sql/sql_ref_left_join.asp)
