15,917,795 members
See more:
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
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.
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.

## Solution 1

Make your select query with Distinct keyword.

For Example :

SQL
`Select Distinct * from TableA Left Outer Join TableB on (TableA.FieldA = TableB.FieldB)`

## Solution 2

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```

## Solution 3

Please, have a look here: Find and/or Delete Duplicate Rows [^]