Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am pretty new to SQL and I already read something about joins , but coudn't find out. I painted my scenario here :

enter image description here

I want to update the Firstname of Table1 into Temp1 where the CreateTS of the matching ID in Table2 is < 08.02.2014

for that I need a join but can't solve it. Any Tips are welcome..

update Table1
set Firstname = 'Temp1'
where Firstame = 'xxx'

join Table
and CreateTS < '2014-02-08 15:00:00.000'
share|improve this question

closed as off-topic by EEAA, Katherine Villyard, Avery Payne, TheCleaner, Falcon Momot Feb 13 '14 at 1:50

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.


update Table1 t1
set t1.Firstname = 'Temp1'    
inner join Table2 t2 on
  t1.Id = t2.Id -- Whatever your PK and FK are here
where t1.Firstame = 'xxx'
and t2.CreateTS < '2014-02-08 15:00:00.000'
share|improve this answer

Here below you have the answer. To highlight the change, I inserted two FirstName as 'not_updated'. Please, see SQL_Fiddle

update Table1
join Table2 on =
set Table1.FirstName = 'Temp1'
where Table2.CreateTS < '2014-02-08  15:00:00.000';

I hope this helps.

share|improve this answer

I wouldn't use join for that. Try:

UPDATE Table1,Table2
SET Table1.FirstName = 'Temp1'
WHERE Table1.FirstName = 'xxx' AND Table1.ID = Table2.ID AND Table2.CreateTS < '2014-02-08 15:00:00.000'
share|improve this answer… don't know if this comes in sql 2012 but 2008 doesn't allow me to update 2 tables. – RayofCommand Feb 12 '14 at 14:24
Oh that really sucks, I didn't know because I only use MySQL. :) – Andrew Feb 12 '14 at 22:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.