Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your question is a little too vague at the moment to really answer fully. What happens to a parent row if it has no children? What happens if some of the child rows have specific values but not all of them? In the two-column case, what combinations of number of children/values are needed (is is the same set of values for each column or unique ones? Is it an AND relationship or an OR relationship)? Etc...</p> <p>Anyway, making the assumption that there needs to be at least one child row with a value in a given domain, this should be fairly straightforward:</p> <pre><code>update PARENT set STATUS = 'whatever' where ID in ( select parent_id from CHILD where value_col in ('your', 'specific', 'values', 'here') ); </code></pre> <p>This general pattern expands to the multi-column case easily (just add an extra AND or ORed condition to the inner where clause), and to the negative case too (change <code>where ID in</code> to <code>where ID not in</code>).</p> <p>If performance of this update is an issue you may want to look at triggers - at the price of slightly slower inserts on the child tables, you can keep your parent table up-to-date on an ongoing basis without having to run this update statement periodically. This works quite nicely because the logic of inspecting each child row is essentially distributed across each individual insert or update on the child table. Of course, if those child modifications are performance-critical, or if the child changes many times in between the points where you need to update the parent, then this wouldn't work very well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload