The UPDATE statement is used to update existing records in a table.

Replace/Delete part of a string

Replace “http://” with “https://” in field

UPDATE users SET website=REPLACE(website,'http://','https://')

Delete a part

UPDATE users SET website=REPLACE(website,'','')

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 to true if is “USA”.

UPDATE account
SET = 1
FROM (SELECT id, country FROM user_info)

Leave a Comment

Your email address will not be published.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.