I want to update GroupID column of massemail\_emailmaster and set it to the value as it is stored on massemail\_groupmaster. Both table has GroupName column which is I have used to join in the subquery.
But the following query is giving me error. Error message is incorrect syntax near a3. I don't understand the mistake in syntax here. Please help.

```
UPDATE [dbo].[massmail_emailmaster]  a3
set a3.GroupId =
      (select TOP 1 a1.GroupID from [dbo].[massmail_groupmaster] a1 
         join [dbo].[massmail_emailmaster] a2
      on a1.[groupname] = a2.[groupname]
where a3.[GroupName]=a2.[GroupName]) 

```

DDL of table `[dbo]. [massmail_emailmaster]`

```
(ClientID, varchar(50)),
           (uid, int)
           (Name, varchar(100))
           (GroupName, varchar(100))
           (Email, varchar(100))
           GroupId, int)

```

DDL of table

```
[dbo]. [massmail_groupmaster]
 (Clientid, varchar(50))
           ,(uid, int)
           ,(groupname, varchar(100))
(GroupId,int))

```