Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Single Query - Update same column in diff table

Author  Topic 

j_kathiresan
Starting Member

3 Posts

Posted - 2014-09-25 : 03:28:27
Hi,

I have two tables table1 and table2 and having a common column "col1"

When i ran the following query

UPDATE table1, table2 SET col1=FALSE WHERE id = 1;

getting the following error

Error Code: 1052
Column 'col1' in field list is ambiguous

id column exist in both the tables and need to update both the tables to false where the id is equivalent to 1.

could you please help me on how to achieve this in single query?

Thanks.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-09-25 : 04:02:38
You need two update statements:

UPDATE TABLE1
SET COL1='FALSE'
WHERE ID = 1

UPDATE TABLE2
SET COL1='FALSE'
WHERE ID = 1


Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

j_kathiresan
Starting Member

3 Posts

Posted - 2014-09-25 : 05:26:25
Is it possible in one single SQL?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-09-25 : 06:54:09
No.

Why do you want it to be done in single sql?

Harsh Athalye
http://in.linkedin.com/in/harshathalye/
Go to Top of Page
   

- Advertisement -