|
-
Dec 10th, 2008, 01:24 PM
#1
Thread Starter
Hyperactive Member
Problem with update query (RESOLVED)
Hi
I am trying to build an update query but keep getting an error that says the column TableB.FirstName does not exist:
update TableA set TableA.emailaddress = TableB.emailaddress where
TableA.firstname = TableB.FirstName and TableA.lastname = Tableb.lastname
Any ideas? Many thanks.
Mike
Last edited by MikeGarvin; Dec 10th, 2008 at 02:25 PM.
-
Dec 10th, 2008, 01:35 PM
#2
Addicted Member
Re: Problem with update query
Why do you have two tables with the same data? Is one an archive/backup of some sort?
In any case, would this work?
Code:
Update TableA set emailaddress =
(Select TableB.emailaddress
From TableA, TableB
Where TableA.firstname = TableB.firstname
And TableA.lastname = TableB.lastname)
If not, someone more experienced may be able to help.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
Dec 10th, 2008, 01:47 PM
#3
Thread Starter
Hyperactive Member
Re: Problem with update query
Thanks. I get this error:
You can't specify target table 'TableA' for update in FROM clause
-
Dec 10th, 2008, 02:24 PM
#4
Thread Starter
Hyperactive Member
Re: Problem with update query
Here is the solution:
UPDATE tablea INNER JOIN tableb ON (tablea.lastname = tableb.lastname) AND (tablea.firstname = tableb.firstname) SET tablea.emailaddress = tableb.emailaddress
-
Dec 10th, 2008, 02:51 PM
#5
Re: Problem with update query (RESOLVED)
I would normally write like this:
sql Code:
Update TableA Set
TableA.EmailAddress = TableB.EmailAddress
Inner Join TableB On
TableA.FirstName = TableB.FirstName And
TableA.LastName = TableB.LastName
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Dec 10th, 2008, 10:50 PM
#6
Re: Problem with update query (RESOLVED)
You could also try this.
Code:
UPDATE TableA SET
TableA.EmailAddress = TableB.EmailAddress
FROM TableA INNER JOIN TableB ON
TableA.FirstName = TableB.FirstName AND
TableA.LastName = TableB.LastName
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|