If you want from more than one table you should have a where
clause or you will end up overriding the previous update operation to nulls,
in other words you will have problem of xTable.newColumn
being set to null
for rows of xTable
that had no matching
key in yTable
and don't worry the where clause will solve this problem, simply add this where clause:
xTable.itsId =(the same select statement in valueComputed but select Id instead)
here is a real example
<changeSet id="0.0.6.1" author="bmomani">
.....
<update tableName="change">
<column name="WIDGET_ID" valueComputed="(SELECT insert_widget.WIDGET_ID FROM insert_widget WHERE change.ID = insert_widget.ID)"/>
<where>change.id = (SELECT insert_widget.ID FROM insert_widget WHERE change.ID = insert_widget.ID)</where>
</update>
<update tableName="change">
<column name="WIDGET_ID" valueComputed="(SELECT remove_widget.WIDGET_ID FROM remove_widget WHERE change.ID = remove_widget.ID)">
</column>
<where>change.id = (SELECT remove_widget.ID FROM remove_widget WHERE change.ID = remove_widget.ID)</where>
</update>
<comment>note that we can do this in one update statement if we used union</comment>
<comment> optional to drop column</comment>
<!--<dropColumn tableName="insert_widget" columnName="widget_id"/>-->
<!--<dropColumn tableName="remove_widget" columnName="widget_id"/>-->
</changeSet>
in this snippet, I wanted to move widget_id
column from insert_widget
table to change
table, but change table already has data, so I have to use update statement
thanks to this answer here https://stackoverflow.com/a/224807/4251431 it helped me figure out the query