Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

SQL Query - Should be easy fix???

$
0
0
Hi,Sorry I know this is going to be an easy fix but I'm just starting out with SQL scripting.I have the following query which has inner joins and is fine on the first join however when I enter the second join the results are wrong scripting ok up to this point:SELECT a.CLIENT_ID ,a.SITE_ID ,a.AUDIT_DATE ,b.VARIABLE_NAME ,a.TOTALFROM MMA_KPIVAR_DAT AS a INNER JOIN MMA_KPIVAR_MST AS b ON a.VARIABLE_ID=b.VARIABLE_IDWHERE a.CLIENT_ID=17 AND a.SITE_ID=57--THIS PRODUCES RESULTS AS EXPECTED--However when I add the next join:SELECT a.CLIENT_ID ,a.SITE_ID ,a.AUDIT_DATE ,b.VARIABLE_NAME ,a.TOTAL ,c.SITE_NAMEFROM MMA_KPIVAR_DAT AS a INNER JOIN MMA_KPIVAR_MST AS b ON a.VARIABLE_ID=b.VARIABLE_ID INNER JOIN MMA_SITE_MST AS c ON a.SITE_ID=c.SITE_IDWHERE a.CLIENT_ID=17 AND a.SITE_ID=57I get instead of getting the site name I get multiple sites with the same results and the same date??I think it is something to do with the date as the data for all rows is duplicated for all sites but is the correct data for CLIENT_ID=17 & SITE_ID=57I have tried different joins e.g. started with MMA_SITE_MST and built it that way only to return the same resultsAny help would be much appreciatedThanksJ

Viewing all articles
Browse latest Browse all 3145

Trending Articles