SQL Query to delete duplicate values in a 3 tables inner join with two different databases

后端 未结 1 1915
一整个雨季
一整个雨季 2021-01-24 22:23

I am working with a SQL Server database and I have written the following query:

SELECT 
    \"AM-Martin\".dbo.CpCore_Site.Latitude,\"AM-Martin\".dbo.CpCore_Site.         


        
相关标签:
1条回答
  • 2021-01-24 23:14

    I figured it out thanks to group by clause is not working with Image all I had to do was add alter the image column wording by CASTing it to VARBINARY like this:

    SELECT 
        "AM-Martin".dbo.CpCore_Site.Number,"AM-Martin".dbo.CpCore_Site.Latitude,"AM-Martin".dbo.CpCore_Site.Longitude,"AM-Martin".dbo.CpSm_Face.RetiredOn,**CAST("AM-Martin_bin".dbo.CpCore_Image.Bytes as Varbinary)**, "AM-Martin".dbo.CpCore_Site.Name, "AM-Martin".dbo.CpCore_Site.Zipcode
    FROM
        "AM-Martin".dbo.CpCore_Site
    
    INNER JOIN "AM-Martin".dbo.CpSm_Face on "AM-Martin".dbo.CpSm_Face.SiteId = "AM-Martin".dbo.CpCore_Site.Oid
    INNER JOIN "AM-Martin_bin".dbo.CpCore_Image on "AM-Martin".dbo.CpSm_Face.Oid = "AM-Martin_bin".dbo.CpCore_Image.OwnerId
    
    WHERE
        "AM-Martin".dbo.CpSm_Face.RetiredOn LIKE '%9999%'
    
         AND "AM-Martin".dbo.CpCore_Site.Number LIKE N'%LA%' OR "AM-Martin".dbo.CpCore_Site.Number LIKE N'%LC%' OR "AM-Martin".dbo.CpCore_Site.Number LIKE N'%BH%'
    
    
         AND "AM-Martin".dbo.CpCore_Site.Latitude > 0.0
    
    GROUP BY "AM-Martin".dbo.CpCore_Site.Number,"AM-Martin".dbo.CpCore_Site.Latitude,"AM-Martin".dbo.CpCore_Site.Longitude,"AM-Martin".dbo.CpSm_Face.RetiredOn,**CAST("AM-Martin_bin".dbo.CpCore_Image.Bytes as Varbinary)**, "AM-Martin".dbo.CpCore_Site.Name, "AM-Martin".dbo.CpCore_Site.Zipcode;
    

    I also have to give @Myonara credit for getting me on the right track with the group by suggestion.

    0 讨论(0)
提交回复
热议问题