473,408 Members | 1,601 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,408 software developers and data experts.

Query to Replace Columns

Here is a sample of what I want to do:

Table 1
ID FIELD1 FIELD2
1 A T
2 G C
3 T C

Table2
ID FIELD1 FIELD2
1 1 4
2 3 2
3 4 3
I want to update the values of FIELD1 and FIELD2 in table1 with the values
in table two. The end result should be that Table 1 looks like Table 2. The
changes must be made for each matching ID between the two tables.

TIA

Stuart E. Wugalter
wu******@usc.edu
Nov 12 '05 #1
4 5135
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're replacing text with numbers - is that what you want to do? If
so, do you want to change the data type of the columns, also - from
text to numeric?

To simply replace values (Query design - SQL view):

UPDATE Table1 As T1 INNER JOIN Table2 As T2
ON T1.ID = T2.ID
SET T1.Field1 = T2.Field1,
T1.Field2 = T2.Field2

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5XMPoechKqOuFEgEQKKzwCgnWlnMntPNz2eITzHjL5k5c A9tG0An0Pi
bwAGsGO+DNF4uU1XFTx/vvrS
=86cv
-----END PGP SIGNATURE-----
Stuart E. Wugalter wrote:
Here is a sample of what I want to do:

Table 1
ID FIELD1 FIELD2
1 A T
2 G C
3 T C

Table2
ID FIELD1 FIELD2
1 1 4
2 3 2
3 4 3
I want to update the values of FIELD1 and FIELD2 in table1 with the values
in table two. The end result should be that Table 1 looks like Table 2. The
changes must be made for each matching ID between the two tables.

TIA

Stuart E. Wugalter
wu******@usc.edu


Nov 12 '05 #2
Thank you very much for your reply. I tested it on the sample data I posted
and it worked great. Then I tried it one the actual tables. It did not work.
Here is the SQL command I used:

UPDATE [tbl Master Table] AS T1, NewProbeData AS T2 SET T1.OrderNum =
T2.OrderNum, T1.SNPID = T2.SNPID, T1.A1=T2.A1, T1.A2=T2.A2;
tbl Master Table has about 270 records and NewProbeData has about 240
records. The query asked me if I wanted to update 93,000 rows.

What am I doing wrong now? TIA

Stuart E. Wugalter
wu******@usc.edu
"MGFoster" <me@privacy.com> wrote in message
news:__***************@newsread3.news.pas.earthlin k.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're replacing text with numbers - is that what you want to do? If
so, do you want to change the data type of the columns, also - from
text to numeric?

To simply replace values (Query design - SQL view):

UPDATE Table1 As T1 INNER JOIN Table2 As T2
ON T1.ID = T2.ID
SET T1.Field1 = T2.Field1,
T1.Field2 = T2.Field2

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5XMPoechKqOuFEgEQKKzwCgnWlnMntPNz2eITzHjL5k5c A9tG0An0Pi
bwAGsGO+DNF4uU1XFTx/vvrS
=86cv
-----END PGP SIGNATURE-----
Stuart E. Wugalter wrote:
Here is a sample of what I want to do:

Table 1
ID FIELD1 FIELD2
1 A T
2 G C
3 T C

Table2
ID FIELD1 FIELD2
1 1 4
2 3 2
3 4 3
I want to update the values of FIELD1 and FIELD2 in table1 with the values in table two. The end result should be that Table 1 looks like Table 2. The changes must be made for each matching ID between the two tables.

TIA

Stuart E. Wugalter
wu******@usc.edu

Nov 12 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You've created a "cartesian join" query, which means that all possible
combinations of the two tables will be created in the result set
(update set). You forgot to INNER JOIN the two tables on the ID
columns.

Is the column "SNPID" really an updateable column? Wasn't it supposed
to be the ID column you had in your first post? Though it won't
matter if you overwrite the T1 SNPID with T2 SNPID's value ('cuz
they're both supposed to be the same) it would be more efficient to
not overwrite the ID column.

If the SNPID is really the ID column for each table here's my re-write
of your query:

UPDATE [tbl Master Table] AS T1 INNER JOIN NewProbeData AS T2
ON T1.SNPID = T2.SNPID
SET T1.OrderNum = T2.OrderNum,
T1.A1 = T2.A1,
T1.A2 = T2.A2;

If you don't want to use the INNER JOIN syntax you can do the same
thing like this:

UPDATE [tbl Master Table] AS T1, NewProbeData AS T2
SET T1.OrderNum = T2.OrderNum,
T1.A1 = T2.A1,
T1.A2 = T2.A2
WHERE T1.SNPID = T2.SNPID

This was the "old" way to create an inner join.

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5b7WIechKqOuFEgEQIM9wCeNoO6S0Egh8tNaly2ry0K+6 qCYw4AoNpH
dWdx09xQZAdVnrDVRM/q3jlo
=OIxN
-----END PGP SIGNATURE-----

Stuart E. Wugalter wrote:
Thank you very much for your reply. I tested it on the sample data I posted
and it worked great. Then I tried it one the actual tables. It did not work.
Here is the SQL command I used:

UPDATE [tbl Master Table] AS T1, NewProbeData AS T2 SET T1.OrderNum =
T2.OrderNum, T1.SNPID = T2.SNPID, T1.A1=T2.A1, T1.A2=T2.A2;
tbl Master Table has about 270 records and NewProbeData has about 240
records. The query asked me if I wanted to update 93,000 rows.

What am I doing wrong now? TIA

Stuart E. Wugalter
wu******@usc.edu
"MGFoster" <me@privacy.com> wrote in message
news:__***************@newsread3.news.pas.earthlin k.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're replacing text with numbers - is that what you want to do? If
so, do you want to change the data type of the columns, also - from
text to numeric?

To simply replace values (Query design - SQL view):

UPDATE Table1 As T1 INNER JOIN Table2 As T2
ON T1.ID = T2.ID
SET T1.Field1 = T2.Field1,
T1.Field2 = T2.Field2

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5XMPoechKqOuFEgEQKKzwCgnWlnMntPNz2eITzHjL5k5c A9tG0An0Pi
bwAGsGO+DNF4uU1XFTx/vvrS
=86cv
-----END PGP SIGNATURE-----
Stuart E. Wugalter wrote:
Here is a sample of what I want to do:

Table 1
ID FIELD1 FIELD2
1 A T
2 G C
3 T C

Table2
ID FIELD1 FIELD2
1 1 4
2 3 2
3 4 3
I want to update the values of FIELD1 and FIELD2 in table1 with the
values
in table two. The end result should be that Table 1 looks like Table 2.
The
changes must be made for each matching ID between the two tables.

TIA

Stuart E. Wugalter
wu******@usc.edu



Nov 12 '05 #4
Thanks for your help! It worked like a charm of course...it would have been
nice if I actually read your first post more carefully ;-) tc Stuart

"MGFoster" <me@privacy.com> wrote in message
news:kX****************@newsread3.news.pas.earthli nk.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You've created a "cartesian join" query, which means that all possible
combinations of the two tables will be created in the result set
(update set). You forgot to INNER JOIN the two tables on the ID
columns.

Is the column "SNPID" really an updateable column? Wasn't it supposed
to be the ID column you had in your first post? Though it won't
matter if you overwrite the T1 SNPID with T2 SNPID's value ('cuz
they're both supposed to be the same) it would be more efficient to
not overwrite the ID column.

If the SNPID is really the ID column for each table here's my re-write
of your query:

UPDATE [tbl Master Table] AS T1 INNER JOIN NewProbeData AS T2
ON T1.SNPID = T2.SNPID
SET T1.OrderNum = T2.OrderNum,
T1.A1 = T2.A1,
T1.A2 = T2.A2;

If you don't want to use the INNER JOIN syntax you can do the same
thing like this:

UPDATE [tbl Master Table] AS T1, NewProbeData AS T2
SET T1.OrderNum = T2.OrderNum,
T1.A1 = T2.A1,
T1.A2 = T2.A2
WHERE T1.SNPID = T2.SNPID

This was the "old" way to create an inner join.

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5b7WIechKqOuFEgEQIM9wCeNoO6S0Egh8tNaly2ry0K+6 qCYw4AoNpH
dWdx09xQZAdVnrDVRM/q3jlo
=OIxN
-----END PGP SIGNATURE-----

Stuart E. Wugalter wrote:
Thank you very much for your reply. I tested it on the sample data I posted and it worked great. Then I tried it one the actual tables. It did not work. Here is the SQL command I used:

UPDATE [tbl Master Table] AS T1, NewProbeData AS T2 SET T1.OrderNum =
T2.OrderNum, T1.SNPID = T2.SNPID, T1.A1=T2.A1, T1.A2=T2.A2;
tbl Master Table has about 270 records and NewProbeData has about 240
records. The query asked me if I wanted to update 93,000 rows.

What am I doing wrong now? TIA

Stuart E. Wugalter
wu******@usc.edu
"MGFoster" <me@privacy.com> wrote in message
news:__***************@newsread3.news.pas.earthlin k.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're replacing text with numbers - is that what you want to do? If
so, do you want to change the data type of the columns, also - from
text to numeric?

To simply replace values (Query design - SQL view):

UPDATE Table1 As T1 INNER JOIN Table2 As T2
ON T1.ID = T2.ID
SET T1.Field1 = T2.Field1,
T1.Field2 = T2.Field2

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP5XMPoechKqOuFEgEQKKzwCgnWlnMntPNz2eITzHjL5k5c A9tG0An0Pi
bwAGsGO+DNF4uU1XFTx/vvrS
=86cv
-----END PGP SIGNATURE-----
Stuart E. Wugalter wrote:

Here is a sample of what I want to do:

Table 1
ID FIELD1 FIELD2
1 A T
2 G C
3 T C

Table2
ID FIELD1 FIELD2
1 1 4
2 3 2
3 4 3
I want to update the values of FIELD1 and FIELD2 in table1 with the


values
in table two. The end result should be that Table 1 looks like Table 2.


The
changes must be made for each matching ID between the two tables.

TIA

Stuart E. Wugalter
wu******@usc.edu


Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Debbie Davis | last post by:
Hi there, SQL 2000 I have the following query: SELECT sponsor, COUNT(sponsor) * 2 AS total FROM Referrals GROUP BY sponsor Works great, returns the sponsor and the total * 2 of their...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
11
by: Andy Fish | last post by:
Hi, I am trying to concoct a query that will join rows on the basis of a whitespace insensitive comparison. For instance if one row has the value 'a<space>b' and another has the value...
15
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
12
by: strict9 | last post by:
Hello all, I'm writing several queries which need to do various string formating, including changing a phone number from (123) 456-7890. After some problem with data mismatches, I finally got it...
8
by: annecarterfredi | last post by:
query the syscat.columns table and prepare SELECT statement (SELECT all_columns FROM table_name). For example, let's say that TAB_1 table has total of three columns, and the statement should be: ...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
6
by: Peter Herath | last post by:
I want to create a dynamic report using a crosstab query...... pls someone look into my attached example database and help me out to do the report generation.... example is like dis...: there...
0
by: Peter Herath | last post by:
I want to create a custormizable report . For an example, there's a form with four combo boxes and two of them having database tables columns/field names as values in the combo box(one for select row...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.