Replace value in table by condition from two tables

Started by ruschan, Oct 05, 2022, 12:57 AM

Previous topic - Next topic

ruschanTopic starter

Good day.
There are 2 tables:
 Parents (identity card, name, age)
 Children (ID, name, age, parent_id) - parent_id indicates whose child

Let's say you need to set the child's age to 10 if: the child is more than 10 years old and his parent is less than 40 years old.
It turns out to change the value, but only if the condition is in the same table
Click here to view the entire text

UPDATE children c
SET c.age = 10
WHERE c.age > 10

It turns out to combine strings

SELECT, p.age,, c.age
FROM parents p JOIN children c ON = c.parent_id
WHERE p.age < 40 AND c.age > 10

But I don't understand how to use it together.
I'm writing a script in IbExpert
I found this example on the Internet with products and stores. I substituted my values, an ERROR
Click here to view the entire text

UPDATE products
JOIN stores ON = store_id
SET price = (price * 0.9)
WHERE = 'Store 2';


well, try it, I'm really not quite sure that the firebird will eat that exists, I haven't had anything to do with her for a long time. if it fails then for

UPDATE incomes32
  SET facialacc_cls = 15000000
  WHERE facialacc_cls = 0 AND
                FROM quotestitle
                WHERE = incomes32.recordindex AND
                      quotestitle.acceptdate <> 20220000)