sql - Sqlite update with min if smaller than existing -
must misunderstand basic here, have couple tables:
table1 (id, minvalue) table2 (table1id, value)
if run query:
update table1 set minvalue = (select min(value) table2 table1.id == table2.table1id);
i expected values. if run query minvalues remain null:
update table1 set minvalue = min(minvalue, (select min(value) table2 table1.id == table2.table1id));
i updating minvalue multiple tables want make sure stays smaller incoming values still gets updated when minvalue still null.
if want ensure minvalue never gets updated higher current value need add condition apply update rows there exists lower incoming value:
update table1 set minvalue = ( select min(value) table2 table1.id = table2.table1id ) exists ( select value table2 table1.id = table2.table1id , table2.value < table1.minvalue )
Comments
Post a Comment