Description
MindsDB provides two ways of using theUPDATE statement:
-
The regular
UPDATEstatement updates specific column values in an existing table. -
The
UPDATE FROM SELECTstatement updates data in an existing table from a subselect query. It can be used as an alternative toCREATE TABLEorINSERT INTOto store predictions.
Syntax
Here is an example of the regularUPDATE statement:
Please replace the placeholders as follows:
integration_nameis the name of the connected data source.table_nameis the table name within that data source.column_nameis the column name within that table.
UPDATE FROM SELECT statement that updates a table with predictions made within MindsDB:
UPDATE FROM SELECT statement that updates a table with predictions. This syntax is easier to write.
The steps followed by the syntax:
- It executes query from the
FROMclause to get the output data. In our example, we query for predictions, but it could be a simple select from another table. Please note that it is aliased asprediction_data. - It updates all rows from the
table_to_be_updatedtable (that belongs to theintegration_to_be_updatedintegration) that match theWHEREclause criteria. The rows are updated with values as defined in theSETclause.
It is recommended to use the primary key column(s) in the WHERE clause (here,
column1 and column2), as the primary key column(s) uniquely identify each row. Otherwise, the UPDATE statement may lead to unexpected results by altering rows that you didn’t want to affect.