Sae
Sae

Reputation: 505

Update Query From 2 Table

I have the below 2 tables:

table1 is tracsName,tracsid,N,NE... table2 is Tracs,kode,N2.... I want to change N value with N2 value with this code, the N and more is the wind arrow

Update query, can more simple? UPDATE table1 SET N=(select N2 from table2 where tracs='daraname2' AND kode='1-6'), NE=(select NE2 from table2 where tracs='daraname2' AND kode='1-6'), E=(select E2 from table2 where tracs='daraname2' AND kode='1-6'), SE=(select SE2 from table2 where tracs='daraname2' AND kode='1-6'), S=(select S2 from table2 where tracs='daraname2' AND kode='1-6'), SW=(select SW2 from table2 where tracs='daraname2' AND kode='1-6'), W=(select W2 from table2 where tracs='daraname2' AND kode='1-6'), NW=(select NW2 from table2 where tracs='daraname2' AND kode='1-6') WHERE tracsName='daraname2' AND tracsid='1-6'

I'm having an error, and if you can give me the logic or the code it will be great.

Upvotes: 2

Views: 43

Answers (2)

Giorgi Nakeuri
Giorgi Nakeuri

Reputation: 35790

Here is the general syntax for mysql:

UPDATE TABLE1 a 
JOIN TABLE2 b ON a.name1 = b.name2
SET a.n1 = b.n2

Here is example for sql server:

UPDATE a
SET n1 = b.n2    
FROM TABLE1 a 
JOIN TABLE2 b ON a.name1 = b.name2

Upvotes: 1

Jayanti Lal
Jayanti Lal

Reputation: 1185

try this code

UPDATE  table1

SET     table1.N = table2.n
FROM table2 WHERE name2 = name1 

Upvotes: 1

Related Questions