Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > CREATE TABLE master > ( > m_id INTEGER, > m_value VARCHAR(4) > ); > > <pre> > ✓ > </pre> <!-- --> > CREATE TABLE scheduled > ( > key INTEGER, > s_id INTEGER, > s_value VARCHAR(4), > due TIMESTAMP > ); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO master VALUES (1, 'Buy'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO master VALUES (2, 'Buy'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO scheduled VALUES (1, 1, 'Sell', '2018-01-01 12:00:00'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO scheduled VALUES (2, 2, 'Sell', '2018-01-01 12:00:01'); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO scheduled VALUES (3, 1, 'Buy', '2019-01-01 12:00:00'); > > <pre> > ✓ > </pre> <!-- --> > SELECT * FROM master; > > <pre> > m_id | m_value > :--- | :------ > 1 | Buy > 2 | Buy > </pre> <!-- --> > SELECT * FROM scheduled; > > <pre> > key | s_id | s_value | due > :-- | :--- | :------ | :------------------ > 1 | 1 | Sell | 2018-01-01 12:00:00 > 2 | 2 | Sell | 2018-01-01 12:00:01 > 3 | 1 | Buy | 2019-01-01 12:00:00 > </pre> <!-- --> > BEGIN; > > <pre> > ✓ > </pre> <!-- --> > UPDATE master > SET m_value = > ( > SELECT s_value > FROM scheduled s > WHERE s_id = m_id > AND due <= CURRENT_DATE > ); > > <pre> > ✓ > </pre> <!-- --> > DELETE FROM scheduled > WHERE s_id IN (SELECT m_id FROM master) > AND s_value = 'Sell'; > > <pre> > ✓ > </pre> <!-- --> > SELECT * FROM scheduled; > > <pre> > key | s_id | s_value | due > :-- | :--- | :------ | :------------------ > 3 | 1 | Buy | 2019-01-01 12:00:00 > </pre> <!-- --> > COMMIT; > > <pre> > ✓ > </pre> <!-- --> > SELECT * FROM master; > > <pre> > m_id | m_value > :--- | :------ > 1 | Sell > 2 | Sell > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=sqlite_3.8&fiddle=925d9396b7ec2e2b75827d8e382a690a)*
back to fiddle