Dkong
Dkong

Reputation: 2788

Linq to Sql Distinct is returning multiple rows

How can I produce something like this with Linq? I'm trying to work something out, this is related to my other post, but my distinct keeps coming back with more rows than expected

Add Conditional Join Dynamically with Linq

select distinct c.CompanyID, c.CompanyName from Company c
left join CompanyIndustry ci
on c.companyid = ci.companyid
left join CompanyService cs
on c.CompanyID = cs.CompanyID
where cs.ServiceID = 6 and ci.IndustryID = 4

Upvotes: 0

Views: 331

Answers (2)

Beth
Beth

Reputation: 9607

If your companyID has more than one related industry or service, you'll get more than one row per company.

Upvotes: 2

JonH
JonH

Reputation: 33153

You should use GROUP BY Not distinct

Upvotes: 1

Related Questions