Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use a conditional statement with the UPDATE query to update the specific field only if it has a certain value, and keep it unchanged otherwise.

For example, the following query updates the 'status' field to 'completed' only if the 'id' is equal to 1, and keeps it unchanged for all other records:

UPDATE table_name
SET status = 'completed'
WHERE id = 1 AND status != 'completed';

In this query, the AND status != 'completed' condition ensures that the status field is not updated if it already has the value 'completed'.

Similarly, you can use different conditions to update specific fields based on other criteria.