473,408 Members | 2,888 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.

Problem With SQL UPDATE

SAM
HI,
I want to know if is possible to update Table1.Col5 from an
Table2.Col3 ??
The Problem is Col1 and Col2 doesn't have a same size.
Exemple of record.

Table 1
Col1 Col2 Col3 Col4 Col5
10 4001 F1 1 NULL
10 4001 F1 1 NULL
10 4003 F5 3 NULL
Table 2
Col1 Col2 Col3
10 4001 S
10 4001 P
10 5009 S
24 4001 P

I tried to update T1.Col5 with T2.Col3 by i got this result
I used INNER join Table1 and Table2 on Col1 and Col2.

Table 1
Col1 Col2 Col3 Col4 Col5
10 4001 F1 1 S
10 4001 F1 1 S
10 4003 F5 3 NULL

Can you help me please.
Thanks in advance.

Feb 15 '08 #1
3 1308
"SAM" <sa****@hotmail.comwrote in message
news:5f**********************************@i29g2000 prf.googlegroups.com...
HI,
I want to know if is possible to update Table1.Col5 from an
Table2.Col3 ??
The Problem is Col1 and Col2 doesn't have a same size.
Exemple of record.

Table 1
Col1 Col2 Col3 Col4 Col5
10 4001 F1 1 NULL
10 4001 F1 1 NULL
10 4003 F5 3 NULL
Table 2
Col1 Col2 Col3
10 4001 S
10 4001 P
10 5009 S
24 4001 P

I tried to update T1.Col5 with T2.Col3 by i got this result
I used INNER join Table1 and Table2 on Col1 and Col2.

Table 1
Col1 Col2 Col3 Col4 Col5
10 4001 F1 1 S
10 4001 F1 1 S
10 4003 F5 3 NULL

Can you help me please.
Thanks in advance.
I don't understand what end result you want. Please could you post your
required results together with some explanation. I'd guess:

UPDATE table1
SET col5 =
(SELECT col3
FROM table2
WHERE table2.col1 = table1.col1
AND table2.col2 = table2.col2);

--
David Portas
Feb 15 '08 #2
SAM
On Feb 15, 3:30*pm, "David Portas"
<REMOVE_BEFORE_REPLYING_dpor...@acm.orgwrote:
"SAM" <sab...@hotmail.comwrote in message

news:5f**********************************@i29g2000 prf.googlegroups.com...


HI,
I want to know if is possible to update *Table1.Col5 from an
Table2.Col3 ??
The Problem is Col1 and Col2 doesn't have a same size.
Exemple of record.
Table 1
Col1 Col2 *Col3 Col4 Col5
10 * *4001 *F1 * *1 * *NULL
10 * *4001 *F1 * *1 * *NULL
10 * *4003 *F5 * *3 * *NULL
Table 2
Col1 Col2 Col3
10 * 4001 * S
10 * 4001 * P
10 * 5009 * S
24 * 4001 * P
I tried to update T1.Col5 with T2.Col3 by i got this result
I used INNER join Table1 and Table2 on Col1 and Col2.
Table 1
Col1 Col2 *Col3 Col4 Col5
10 * *4001 *F1 * *1 * *S
10 * *4001 *F1 * *1 * *S
10 * *4003 *F5 * *3 * *NULL
Can you help me please.
Thanks in advance.

I don't understand what end result you want. Please could you post your
required results together with some explanation. I'd guess:

UPDATE table1
SET col5 =
*(SELECT col3
* FROM table2
* WHERE table2.col1 = table1.col1
* *AND table2.col2 = table2.col2);

--
David Portas- Hide quoted text -

- Show quoted text -
HI,
I got this result
Table 1
Col1 Col2 Col3 Col4 Col5
10 4001 F1 1 S
10 4001 F1 1 S
10 4003 F5 3 NULL
but
my required results is

Table 1
Col1 Col2 Col3 Col4 Col5
10 4001 F1 1 S
10 4001 F1 1 P<--------
10 4003 F5 3 NULL
i want a 'P' en the second record not a 'S'
thanks for your help
Feb 15 '08 #3
"SAM" <sa****@hotmail.comwrote in message
news:4a**********************************@i29g2000 prf.googlegroups.com...
i want a 'P' en the second record not a 'S'
Please explain how you arrive at that result. Also, what are the keys of the
two tables? Every table should have a key but Table1 has none that I can
see. As Erland says, the easiest way to describe your problem is to post a
CREATE TABLE (with keys please) and some INSERTs.

--
David Portas
Feb 16 '08 #4

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

Similar topics

2
by: Ray | last post by:
I have a list of about 20,000 rows that I am updating. I loop through each row in my program and basically do the following (1) select * from TABLE where SID= for update /*lock the row*/ (2)...
7
by: Zachary Hilbun | last post by:
The below is some test code to help me learn how to update a dataset. It is supposed to read the value of UserCounter and write it back. The UserCounter is being read correctly as 0, is 1 when...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
2
by: Tom Larard | last post by:
Hi, We have an app which uses the latest version of perl DBI and DBD::Pg to execute a query, using placeholders. It fails to cast the float I send into a number and generates the following...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
15
by: Scotty | last post by:
I like to have a good insert, update and delete code The code below sometimes workl ok sometimes doesnt work, what i am doing wrong?? Sub SaveAny() Dim command_builder As New...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.