Reputation: 321
I have two tables..
Persons:
empid(primary key)
firstname
lastname
email
Details:
Did(primary key)
salary
designation
empid
Now I need to UPDATE email of the employee whose name is 'abc' AND designation is Manager.(lets suppose there are more than one employees names abc and therefore designation needs to be checked) I am using sql server 2008
Upvotes: 1
Views: 12807
Reputation: 1
Try This:
UPDATE
[Persons]
SET
[Persons].[email]='###@###.###'
FROM
[Persons]
INNER JOIN [Persons].[empid]
ON [Details].[empid] = [Persons].[empid]
WHERE
[Persons].[firstname]='abc' AND
[Details].[designation]='Manager'
Upvotes: 0
Reputation: 280272
UPDATE p
SET email = '[email protected]'
FROM dbo.Persons AS p
INNER JOIN dbo.Details AS d
ON p.empid = d.empid
WHERE p.firstname = 'abc'
AND d.Designation = 'manager';
Upvotes: 7