How to Update the Col2 for below Table Structure [message #674894] |
Thu, 21 February 2019 04:41 |
sonudev
Messages: 26 Registered: November 2009 Location: bangalore
|
Junior Member |
|
|
Hi,
We have the below structure for two tables. Now I want to sort out the below queries.
Tab1
C1 C2 C3
10 20 78
70 50 76
80 90 79
Tab2
C1 C2
10 X
70 Y
80 Z
How can we update C2 column of tab1 with the values as per second table tab2 ?
How to get max value from the table tab1?
Appreciate for valuable suggestions.
Thanks,
Sonu
|
|
|
Re: How to Update the Col2 for below Table Structure [message #674895 is a reply to message #674894] |
Thu, 21 February 2019 04:56 |
cookiemonster
Messages: 13925 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Correlated sub-query:
UPDATE tab1
SET c2 = (SELECT c2 FROM tab2 WHERE tab2.c1 = tab1)
WHERE c1 IN (SELECT c1 FROM tab2);
Merge:
MERGE INTO tab1 t1
USING (SELECT c1, c2
FROM tab2) t2
ON t1.c1 = t2.c1
WHEN MATCHED THEN
UPDATE SET t1.c2 = t2.c2
As for max:
SELECT max(whatever column) FROM table;
|
|
|
|
|
|
|
|
|