Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 join help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2012-07-31 : 11:23:36
I am doing now

select * from registration r left join accesstype a on r.type=atype

now it's giving me all records from r but if there are 2 matching records in a then it gives me the record twice from r

how can i have it do it but only giving me 1 record from r (I thought left join was supposed to do that but it doesn't seem to be working)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-31 : 11:53:57
[code]
select distinct r.* from registration r
left join accesstype a on r.type=atype
[/code]

if you want fields from a you need to apply some aggregation over them like SUM(),MIN(),MAX() etc to void duplicating r table values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -