English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Help to update 1 field in a table where the data is in another table and one field is matching ? SQL DB2 query please ?

2007-02-26 17:13:36 · 2 answers · asked by shiva 1 in Computers & Internet Programming & Design

2 answers

As far as I know, but I haven't used DB2 for about 11 years, there is not a lot of difference in the SQL

Have you tried
UPDATE table1 a
SET a.column1 = (SELECT b.column2 FROM table2 b
WHERE a.column3 = b.column4);

This will update every row in table 1 based on column3 and column4 being the joining columns. This will update every row on table1. If there is not a matching row on table 2, column1 will be set to null. If you only want to update rows that do have a match include
AND EXISTS (SELECT 'x' FROM table2 c
WHERE a.column3 = c.column4);

2007-02-28 04:08:08 · answer #1 · answered by Elizabeth Howard 6 · 0 0

Sorry, SQL Server 2005

http://www.sql-ex.ru/dmlexercises.php

2007-02-27 03:05:42 · answer #2 · answered by Serge M 6 · 0 0

fedest.com, questions and answers