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
 General SQL Server Forums
 New to SQL Server Programming
 Join returning multiple duplicate rows

Author  Topic 

neb2886
Starting Member

4 Posts

Posted - 2012-03-09 : 14:51:36
I am trying to join two tables by the IP Address column using the following query however I am receiving multiple (3 records) for each IP address. Can you see something wrong here?


SELECT
smachIPAddress,
ScanDate,
ScanName,
pspplMSSeverity,
PatchMissing

FROM
(
SELECT
SDA.smachIPAddress,
SDA.ScanDate,
SDA.ScanName,
PDA.pspplMSSeverity,
SDA.PatchMissing,

DENSE_RANK() OVER (ORDER BY SDA.ScanDate DESC) AS Rnk

FROM qryReportsScanSummaryWithDetailsAggregate SDA

LEFT OUTER JOIN qryReportsPatchStatusDetailAggregate PDA
ON SDA.smachIPAddress = PDA.smachIPAddress

WHERE SDA.ScanName LIKE '%fisma-mgmt%'
and PDA.pspplMSSeverity like '0'
or PDA.pspplMSSeverity like '1'
or PDA.pspplMSSeverity like '2'

GROUP BY
SDA.smachIPAddress,
SDA.ScanDate,
SDA.ScanName,
PDA.pspplMSSeverity,
SDA.PatchMissing

)t
WHERE rnk=1

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 21:46:46
not without seeing data from tables. post some data and explain what you mean by duplicates

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

Go to Top of Page
   

- Advertisement -