473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to update A Single Column data from one table into another..

chiragvithlani
In SQL Server 2005... with some 11K rows

I am having two tables T1 and T2(as bkup of T1), now i need one column data of T2 as i accidently updated T1 column data, (Update T1.colx with T2.colx)

I tried with

<code> update T1 set colx=(select colx from T2) </code>

but this is syntactically wrong as subquery returns multiple rows,

If i try with..

<code> insert into T1 (colx) select T2.colx from T2 as T2_1 cross join T2 </code> it will append and i dont need to append but update....

Copy paste is also not working... Can some one help !!!
Oct 28 '07 #1
6 6391
Jim Doherty
897 Expert 512MB
In SQL Server 2005... with some 11K rows

I am having two tables T1 and T2(as bkup of T1), now i need one column data of T2 as i accidently updated T1 column data, (Update T1.colx with T2.colx)

I tried with

<code> update T1 set colx=(select colx from T2) </code>

but this is syntactically wrong as subquery returns multiple rows,

If i try with..

<code> insert into T1 (colx) select T2.colx from T2 as T2_1 cross join T2 </code> it will append and i dont need to append but update....

Copy paste is also not working... Can some one help !!!

Expand|Select|Wrap|Line Numbers
  1.  UPDATE t1
  2. SET t1.colx=t2.colx
  3. FROM t1,t2

Regards

Jim :)
Oct 28 '07 #2
hello jim,

the code above you mentioned just updated the destination column with only First Row Value.... !!!!!! i.e. 'yes' of my T2.colx

yes
yes
yes


But My Table Column Contained Values like...

yes
no
none (etc..)


your suggested code updated all T1.colx with 'yes' where i have different values for 11k rows....

Can you tell what must be the problem and how to update T1.colx from T2.colx

Thanks 1`s again !!

Regards,
Nov 5 '07 #3
amitpatel66
2,367 Expert 2GB
hello jim,

the code above you mentioned just updated the destination column with only First Row Value.... !!!!!! i.e. 'yes' of my T2.colx

yes
yes
yes


But My Table Column Contained Values like...

yes
no
none (etc..)


your suggested code updated all T1.colx with 'yes' where i have different values for 11k rows....

Can you tell what must be the problem and how to update T1.colx from T2.colx

Thanks 1`s again !!

Regards,
You need to add WHERE condition between t1 and t2 to update accordingly.

Expand|Select|Wrap|Line Numbers
  1. UPDATE t1
  2. SET t1.colx=t2.colx
  3. FROM t1,t2
  4. WHERE t1.col1 = t2.col1
  5.  
Nov 5 '07 #4
Jim Doherty
897 Expert 512MB
You need to add WHERE condition between t1 and t2 to update accordingly.

Expand|Select|Wrap|Line Numbers
  1. UPDATE t1
  2. SET t1.colx=t2.colx
  3. FROM t1,t2
  4. WHERE t1.col1 = t2.col1
  5.  

Thanks Amit you got there before me

Jim :)
Nov 5 '07 #5
Thank you Amit,

your code worked, you know i am just learning SQL... Can you suggest me few links where i can get my basics(fundametals) of SQL, I think it got be sounder then i am at....

Regards,

Chirag
Nov 6 '07 #6
amitpatel66
2,367 Expert 2GB
Thank you Amit,

your code worked, you know i am just learning SQL... Can you suggest me few links where i can get my basics(fundametals) of SQL, I think it got be sounder then i am at....

Regards,

Chirag
check out here for SQL fundamentals
Nov 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
0
by: Jim C Nguyen | last post by:
I have a table with ~2.2 million rows. Sometimes when I do an update to one single row it will instead update ALL of the rows using the same update. This happens every one in about 500,000...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
3
by: indabert | last post by:
Hello, I have two tables (table1 and table2). I want to set a flag in table1 for each common row with table2. I use the following syntax UPDATE table1 SET flag='Y' from table1 INNER JOIN table2...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
5
by: Paul M | last post by:
Hi All, I've been tasked with writing a z/OS C program to read and update a table (DB/2 v8). This Table contains a single row with a single column of data. This program (which will run as a...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.