Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem With SQL UPDATE

SAM
Guest
 
Posts: n/a
#1: Feb 15 '08
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.


David Portas
Guest
 
Posts: n/a
#2: Feb 15 '08

re: Problem With SQL UPDATE


"SAM" <saberb@hotmail.comwrote in message
news:5f09267d-5086-4b7e-b945-63dd587167f6@i29g2000prf.googlegroups.com...
Quote:
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


SAM
Guest
 
Posts: n/a
#3: Feb 15 '08

re: Problem With SQL UPDATE


On Feb 15, 3:30*pm, "David Portas"
<REMOVE_BEFORE_REPLYING_dpor...@acm.orgwrote:
Quote:
"SAM" <sab...@hotmail.comwrote in message
>
news:5f09267d-5086-4b7e-b945-63dd587167f6@i29g2000prf.googlegroups.com...
>
>
>
>
>
Quote:
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.
>
Quote:
Table 1
Col1 Col2 *Col3 Col4 Col5
10 * *4001 *F1 * *1 * *NULL
10 * *4001 *F1 * *1 * *NULL
10 * *4003 *F5 * *3 * *NULL
>
Quote:
Table 2
Col1 Col2 Col3
10 * 4001 * S
10 * 4001 * P
10 * 5009 * S
24 * 4001 * P
>
Quote:
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.
>
Quote:
Table 1
Col1 Col2 *Col3 Col4 Col5
10 * *4001 *F1 * *1 * *S
10 * *4001 *F1 * *1 * *S
10 * *4003 *F5 * *3 * *NULL
>
Quote:
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
Quote:
Quote:
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
David Portas
Guest
 
Posts: n/a
#4: Feb 16 '08

re: Problem With SQL UPDATE


"SAM" <saberb@hotmail.comwrote in message
news:4ac7cb13-9b8a-46a3-be44-96c2ea23b8d0@i29g2000prf.googlegroups.com...
Quote:
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


Closed Thread