The UPDATE statement is used to update existing records in a table.
Table of Contents
Replace/Delete part of a string
Replace “http://” with “https://” in users.website field
UPDATE users SET website=REPLACE(website,'http://','https://')
Delete a part
UPDATE users SET website=REPLACE(website,'http://example.com','')
UPDATE query with condition
UPDATE account
SET validated = 0
WHERE email IS null
Update Column +1
If the column is a number, you can set it like this.
UPDATE table
SET column_name = column_name + 1
WHERE id = <any id>
UPDATE query based on SELECT query
We have 2 tables, account and user_info and want to update account.active to true if user_info.country is “USA”.
UPDATE account
SET account.active = 1
FROM (SELECT id, country FROM user_info)
WHERE account.id = user_info.id AND user_info.country = 'USA'