Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to find duplicated values in rows obtained from multiple tables

946607Sep 26 2012 — edited Sep 28 2012
Hi.
I need to find the duplicates stored in different tables of my database. I have some tables like the following model (I know it could be nonsense, but that's because it's simplified):

table person { id, name, surname }.
table zoo {id, owner, name, city} (zoo.owner -> person.id)
table area {id, zoo, type, name} (area.zoo -> zoo.id).
table dog {id, area, name, colour} (dog.area -> area.id)
table elephant {id, area, name, height} (elephant.area -> area.id)

As ids are autoincremental, it could happen that a person has two zoos with identical areas (meaning, these areas has the same type and name, same dogs (same name and colour) and same elephants (same name and height)). In an example with data:

person
id name surname
p1 john doe

zoo
id owner name city
z1 p1 central NY
z2 p1 central NY

area
id zoo type name
a1 z1 open main
a2 z2 open main

dog
id area name colour
d1 a1 jaro brown
d2 a1 chispa white
d3 a2 jaro brown
d4 a2 chispa white

elephant
id area name height
e1 a1 dumbo 5
e2 a1 elphy 4
e3 a2 dumbo 5
e4 a2 elphy 4


That is: John Doe has two zoos in the same city and with the same name. These two zoos, has one open main area each. Each of these areas has two dogs with the same names and colours and two elephants with the same names and heights. So this zoos would be identical. What I want is to delete z2 zoo.

I'd like to find a SQL function which returns me the id of one of these zoos, so it can respond to the question. Has the person called "John Doe" more than one area with the same type, name, dogs and elephants?

Is it possible?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 26 2012
Added on Sep 26 2012
5 comments
1,030 views