I have a master table, say tbl, which has three columns. Say I create a table that only shows the first record that is unique with respect to the combinations of col1 and col2. The SQL for such a table is defined as below:
CREATE TABLE pseudo_view AS SELECT col1, col2, col3 FROM tbl GROUP BY col1 col2
Now I see all unique combinations of col1 and col2 in this new table. I update this table such that col3 for a given record is changed. I want this to apply back to the master table tbl by affecting all duplicate records.
I am aware that this is not possible with a standard view. However, is there a way to create a dependent table, that, when it is updated, the master table will be updated as defined by the select mechanism? I desire a solution such that this pseudo-view table can have its records updated and deleted freely while also affecting the parent table.
It would work with some triggers on the pseudo_view and tbl
For insert, update and delete on tbl the “view” needs to update accordingly. Normally that is easy. The only hard part is when you delete the last pair of col1 and col2.
For update and delete on pseudo_table you need to define what should change on the master.
In my example I’ve choosen to have min(3) as the function so when a row is updated that same row (the one that used to have the smallest col3) is update and a new (possibly the same) value for the psuedotable is calculated.
When a row is deleted all rows in tbl needs to go as they would otherwise have given a row in pseudo as well (and that was just deleted).