This SQLite post explains how to use the SQLite UPDATE statement with syntax and examples.
The SQLite UPDATE statement is used to update existing records in a table in a SQLite database. There are 2 syntaxes for the UPDATE statement depending on the type of update that you wish to perform.
In its simplest form, the syntax for the SQLite UPDATE statement when updating one table is:
However, the full syntax for the SQLite UPDATE statement when updating one table is:
OR
The syntax for the MySQL UPDATE statement when updating one table with data from another table is:
The name of the table that you wish to update.
The columns that you wish to update.
The new values to assign to the column1, column2. So column1 would be assigned the value of expression1, column2 would be assigned the value of expression2, and so on.
Optional. The conditions that must be met for the update to execute.
Optional. It may be used in combination with LIMIT to sort the records appropriately when limiting the number of records to be updated. ASC sorts in ascending order and DESC sorts in descending order.
Optional. If LIMIT is provided, it controls the maximum number of records to update in the table. At most, the number of records specified by number_rows will be update in the table. The first row selected by LIMIT will be determined by offset_value.
Let's look at a very simple SQLite UPDATE query example.
This SQLite UPDATE example would update the last_name to 'Johnson' in the employees table where the employee_id is 1.
Let's look at a SQLite UPDATE example where you might want to update more than one column with a single UPDATE statement.
When you wish to update multiple columns, you can do this by separating the column/value pairs with commas.
This SQLite UPDATE statement example would update the last_name to 'Johnson' and the favorite_website to 'AODBA.com' where the employee_id is equal to 1.
Let's look at an UPDATE example that shows how to update a table with data from another table in SQLite.
This UPDATE example would update only the employees table for all records where the employee_id is greater than 10. The city from the offices table where office_id is equal to 1 would be copied to the city field in the employees table.