Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi to all,

I have using sql server 2005. i try left join query with multiple table.while i get duplicate records. same records occur multiple times please give me solution
Posted
Comments
OriginalGriff 22-Aug-13 4:24am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps showing us the query would help, and some sample of the output you get, and the output you would like?
Use the "Improve question" widget to edit your question and provide better information.

Make your select query with Distinct keyword.

For Example :

SQL
Select Distinct * from TableA Left Outer Join TableB on (TableA.FieldA = TableB.FieldB)
 
Share this answer
 
use Distinct Or Group by according to your requirement..

create table tbl1
(
col1 int,
col2 varchar(10),
col3 varchar(10)
)
insert into tbl1 values(1,'aaa','bbb'),(2,'aaa','bbb'),(3,'bbb','ccc'),(4,'bbb','ccc'),(5,'ccc','xxx')


create table tbl2
(
col1 varchar(10),
col2 varchar(10),

)
insert into tbl2 values('aaa','hello'),('bbb','Hi')


----General left query---

select t1.col2,t1.col3,t2.col2 from tbl1 t1 
left join tbl2 t2
on t1.col2=t2.col1

result:
col2	col3	col2
aaa	bbb	hello
aaa	bbb	hello
bbb	ccc	Hi
bbb	ccc	Hi
ccc	xxx	NULL


---- using distinct----
select distinct t1.col2,t1.col3,t2.col2
from tbl1 t1
left join tbl2 t2
on t1.col2=t2.col1</pre>

result:
col2	col3	col2
aaa	bbb	hello
bbb	ccc	Hi
ccc	xxx	NULL


---Using Group by---
SQL
select t1.col2,t1.col3,t2.col2
from tbl1 t1
left join tbl2 t2
on t1.col2=t2.col1
group by t1.col2,t1.col3,t2.col2

Result:
col2	col3	col2
aaa	bbb	hello
bbb	ccc	Hi
ccc	xxx	NULL
 
Share this answer
 
Please, have a look here: Find and/or Delete Duplicate Rows [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900