I (beginner SQL user) have a SQL Server view, created with the following statement:
CREATE VIEW dbo.v_LSitesGeo AS
SELECT   PS.LSiteID, GEO.geographyColumn
FROM         dbo.Project_SiteID_Lookup AS PS INNER JOIN
             dbo.Geocodio AS GEO ON GEO.ProjectCode = PS.ProjectNumber
WHERE     (NOT (GEO.geographyColumn IS NULL)) AND (NOT (PS.LSiteID IS NULL))
However, the [LSiteID] column has duplicate values in it. I want to filter out any duplicates in the view however, they need to stay in the [Project_SiteID_Lookup] table. All of the [ProjectNumber] values are unique, so I can't use DISTINCT.
I tried to follow this post, however I wasn't able to get the following to work:
SELECT   PS.LSiteID, GEO.geographyColumn
FROM         dbo.Project_SiteID_Lookup AS PS INNER JOIN 
             dbo.Geocodio AS GEO ON GEO.ProjectCode = PS.ProjectNumber
WHERE       0 = (SELECT COUNT(PS.LSiteID) 
            FROM dbo.Project_SiteID_Lookup AS PS, dbo.Project_SiteID_Lookup AS PS2
            WHERE PS2.LSiteID = PS.LSiteID
            AND PS2.LSiteID < PS.LSiteID)
Any advice on how to make the above work, or another method to achieve this, would be much appreciated.
 
     
    