Determining the best method for moving a table and updating another table

I use Delphi 7, BDE and Interbase (testing), Oracle (Production).

I have two tables (Wizard, Answers)

I need to go through the table "Answers", use its field "Master_Id" to view it in the main table (id) to match the record and update the date field in the main table with the date field in the table "Answers"

Can this be done in SQL, or do I really need to create two TTables or TQueries and go through each record?

Example:

Open two tables (Table 1, Table 2)

with Table1 do
begin
 first;
 while not EOF do
 begin
  //get master_id field
  //locate in id field in table 2
  //edit record in table 2
  next;
 end;
end;  

thank

+3
source share
2 answers

, where, , . NULL

UPDATE Master m
SET 
    m.date = (SELECT r.date FROM Reponses r WHERE r.master_id = m.id) 
WHERE m.id IN (SELECT master_id FROM Responses)

, , , . , , UPDATE . , sql- JOIN UPDATE.

UPDATE Master m 
SET      m.date = (
    SELECT MAX(r.date) FROM Reponses r WHERE r.master_id = m.id)  
WHERE m.id IN (SELECT master_id FROM Responses) 

MAX(), , . SQL. . PLSQL, Oracle

+2

SQL ( )

m SET date = (SELECT date FROM Responses WHERE id = m.id)

0

Source: https://habr.com/ru/post/1790778/


All Articles