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 can I avoid duplicates in sql with Joins?

729789Oct 23 2009 — edited Oct 25 2009
Hello People,
I am developing web application using csharp and oracle as a database. I have a three tables where I am pulling from records. But when write sql using inner joins and Outer join the records are being duplicated. These tables are being using joined using three(3) fields That are making up a compound primary key. How can I join them using an sql such that there is no duplicated. I am not allowed to modify the structure of the table. primary keys are in board


the tables are as follows;

Table1

STU_YEAR VARCHAR2(4)
Stu_CUO VARCHAR2(5)
STU_DEC VARCHAR2(17)
STU_NBER VARCHAR2(13)
STU_NBER NUMBER
STU_CODE VARCHAR2(3)
STU_BTCOD VARCHAR2(2)
STU_BASE NUMBER(18,2)
STU_RATE


Table2

STU_YEAR VARCHAR2(4)
Stu_CUO VARCHAR2(5)
STU_DEC VARCHAR2(17)
CUP_CODE VARCHAR2(3)
CUP_BT VARCHAR2(2)



table3

STU_YEAR VARCHAR2(4)
Stu_CUO VARCHAR2(5)
STU_DEC VARCHAR2(17)
KPP_CNAME VARCHAR2(3)
KPP_BTNAME VARCHAR2(2)



sql= "Select STU_YEAR, Stu_CUO,STU_DEC,STU_NBER,STU_NBER,STU_CODE,STU_BTCOD, STU_BASE,STU_RATE,CUP_CODE,KPP_CNAME,KPP_BTNAME FROM Table1 LEFT OUTER JOIN Table2 USING (Stu_CUO) LEFT OUTER JOIN Table3 USING (Stu_CUO)
where Table1.STU_YEAR= Table2.STU_YEAR and Table1.STU_DEC= Table2.STU_DEC and Table1.STU_YEAR= Table3.STU_YEAR and Table1.STU_DEC= Table3.STU_DEC and STU_NBER ='"+ Varible +"'
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 22 2009
Added on Oct 23 2009
14 comments
9,185 views