I am VERY rusty with my SQL, it's been a few years, but I need to write a query to fix something in a table I have.
There are erroneous duplicates where not every column is the same, but I know at least one is.
So I have this query that works:
SELECT 
    [IntMsgID], [SortDate], COUNT(*)
FROM 
    [databasename].[dbo].[tblDoc]
GROUP BY
    [IntMsgID], [SortDate]
HAVING 
    COUNT(*) >= 2 
    AND [IntMsgID] IS NOT NULL
It identifies the documents in question. What I need to do, then, is take the results from that and update another field simply with the value of Y or 1.
I've done searching and it seems any query I've tried to plug in fails, such as
UPDATE [databasename].[dbo].[tblDoc] AS t 
INNER JOIN 
    (SELECT [IntMsgID] msgid 
     FROM [databasename].[dbo].[tblDoc] 
     GROUP BY [IntMsgID]) t1 ON t.[IntMsgID] = t1.[IntMsgID]
SET [JG_SQLDupe] = 'Y'
I get syntax errors at "AS" and "INNER" and "t1"
 
     
    