I need to update col1 in table1 with the highest value in val in table2 that is lower than
col2 in table1. I am trying this:
update table1 set col1 = max(t2.val)
from table2 t2 where t2.VAL < col2
I am getting this error:
An aggregate may not appear in the set list of an UPDATE statement.
Here is sample data
Table1
Col1 Col2
2 null
3 null
4 null
6 null
7 null
8 null
9 null
10 null
Table2
Val
1
5
after I run the query I would want it to look like this:
Table1
Col1 Col2
2 1
3 1
4 1
6 5
7 5
8 5
9 5
10 5
lets initialize t1 (the modified field is the one that will have the
maxvalue fromt2but less than itsvalvalue)this is your table1 (t2) with values …
run the query : …
edit
for your values here is the result :