Skip to content
Advertisement

SQL: Update a table column with data in column retrieved from a view in same procedure

I’m trying to do a select and update within the same local procedure. The idea is to retrieve the number of ordered products from a specific order in the view (Produktantal) and then updating the stock numbers (antal) from the table “produktlager” with the data retrieved from the view.

I’m receiving the follow error message Error: ER_BAD_FIELD_ERROR: Unknown column 'Produktantal' in 'field list'. I don’t seem to be available to access the column in the update part. How can I do this?

The view:

Advertisement

Answer

The two statements in your procedure are executed independently, and the second statement cannot in any way access the results of the first one.

I suspect that you want the update ... join syntax:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement