Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update rows from another table [duplicate]

Tags:

tsql

I have a table with 2 columns, Country and Qty. the field country has distinct acronyms of all the countries. Now my job is to replace those acronyms with the actual country name. Now there is another table with acronyms and corresponding country names. I have to take the values from this second table and update the first one where Acronyms match. Please help..

like image 596
Avinash Avatar asked Apr 15 '11 13:04

Avinash


People also ask

How do you update the same record in SQL?

UPDATE Syntax Notice the WHERE clause in the UPDATE statement. The WHERE clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records in the table will be updated!

How does on duplicate key update work?

ON DUPLICATE KEY UPDATE is a MariaDB/MySQL extension to the INSERT statement that, if it finds a duplicate unique or primary key, will instead perform an UPDATE. The row/s affected value is reported as 1 if a row is inserted, and 2 if a row is updated, unless the API's CLIENT_FOUND_ROWS flag is set.


1 Answers

UPDATE  q SET     country = a.country FROM    quantity q JOIN    acronym a ON      a.acronym = q.country 
like image 69
Quassnoi Avatar answered Oct 13 '22 07:10

Quassnoi