?
Solved

How to eliminate duplicate rows in oracle sql

Posted on 2011-09-15
8
Medium Priority
?
386 Views
Last Modified: 2013-12-19
I know this is stupid question to ask but just giving a try if any one can help me.


I have two tables A & B

Table A Columns
-------------------

ID           AMOUNT
1               100
1               200
1               300
1               400
1               500

Table B columns
--------------------

ID              NO
1               ABC
1               DEF
1               GHI
1               JKL
1               MNO


When I join both the tables I get 5*5 = 25 rows

Is there any way I can get 5 records when I join both the tables with ID as Join ?







0
Comment
Question by:VenkatBunny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 36546352
Add a where clause?

Select t1.id, amount, no
From tableA t1, tableB t2
Where t1.id=t2.I'd;
0
 

Author Comment

by:VenkatBunny
ID: 36546381
I join with ID I still get 25 rows
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36546408
OH, I see it now.

There really aren't duplicates.

How do you relate what amount goes with what NO?

Does 100 go with ABC or MNO?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 36546419
How should your 5 row output look like?
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36546453
You can create an arbitrary join column but there you need to decide on what amount goes with what NO.

The code below produces:


        ID     AMOUNT N
---------- ---------- -
         1        100 a
         1        200 b
         1        300 c
         1        400 d
         1        500 e
drop table tab1 purge;
create table tab1(id number, amount number);

drop table tab2 purge;
create table tab2(id number, no char(1));

insert into tab1 values(1,100);
insert into tab1 values(1,200);
insert into tab1 values(1,300);
insert into tab1 values(1,400);
insert into tab1 values(1,500);

insert into tab2 values(1,'a');
insert into tab2 values(1,'b');
insert into tab2 values(1,'c');
insert into tab2 values(1,'d');
insert into tab2 values(1,'e');
commit;

select t1.id, t1.amount, t2.no
from
(select id, amount, row_number() over(order by amount) t1_rownum from tab1) t1,
(select id, no, row_number() over(order by no) t2_rownum from tab2) t2
where t1.id=t2.id and t1.t1_rownum = t2.t2_rownum;

Open in new window

0
 
LVL 7

Expert Comment

by:Piloute
ID: 36550196
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36550321
Piloute,

Isn't that basically what I posted?
0
 
LVL 7

Expert Comment

by:Piloute
ID: 36891993
Humm,

Yup ! Looks similar.

What I want to point out here is that VenkatBunny probably didn't search for the problem before posting a question...

Cheers,
P
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question