troubleshooting Question

Recordset with joins not working

Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland asked on
ASPMicrosoft SQL Server 2008
4 Comments1 Solution253 ViewsLast Modified:
Hello All,

Small problem with one of my recordset falling down, its multiplying the results from two of the joined tables....

My tables (& columns) are -

dbo.JBAdvert
JBAID
JBATitle
JBADescription
JBAPayRate
JBALocation
JBADatePosted
JBACategory

dbo.JBApplication
JBAPID
JBAPAdvertID

dbo.JBVacancyview
VacancyID
ID

dbo.JBClient
JBCLID
JBCLName
JBCLLogo

I think you can see from below, what I am trying to do, the problem is with COUNT(AV.ID) AS ADViews, COUNT(AP.JBAPID) AS Applications, in that if there have been any applications, it appears to multiply the two values.

Any thoughts really appreciated, .. thank you
Select TOP(40)
AD.JBAID, Lower(AD.JBATitle) AS JBATitle, AD.JBALocation, AD.JBACategory, AD.JBAPayRate, AD.JBADatePosted, Lower(left(AD.JBADescription,300)+'...') as JBADescription, CL.JBCLName, CL.JBCLLogo, COUNT(AV.ID) AS ADViews, COUNT(AP.JBAPID) AS Applications
FROM dbo.JBAdvert AD left join dbo.JBApplication AP on AP.JBAPAdvertID = AD.JBAID left join dbo.JBVacancyview AV on AV.VacancyID = AD.JBAID inner join dbo.JBClient CL on CL.JBCLID = AD.JBAClientID
Where AD.JBASiteID = @SiteID AND JBADatePosted >= DATEADD(d,-JBAPostFor,GETDATE())
GROUP BY AD.JBAID, AD.JBATitle, AD.JBALocation, AD.JBACategory, AD.JBAPayRate, AD.JBADatePosted, AD.JBADescription, CL.JBCLName, CL.JBCLLogo
ORDER BY AD.JBADatePosted DESC
ASKER CERTIFIED SOLUTION
Chris Luttrell
Senior Database Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros