Skip to content

Instantly share code, notes, and snippets.

@cherihung
Last active March 13, 2017 00:55
Show Gist options
  • Save cherihung/7949f0c49a86883f8727 to your computer and use it in GitHub Desktop.
Save cherihung/7949f0c49a86883f8727 to your computer and use it in GitHub Desktop.
handy SQL code snippets
//concatenante strings, column values
UPDATE table
SET column = CONCAT('text', columnname, 'text')
//lowercase values in one column
UPDATE table SET column = LOWER(column)
//update column value based on value matching to same column or different column
UPDATE table SET column = value WHERE column = value
UPDATE table SET column = value WHERE column IS NULL
//update specific cell value in table 1 with value from a specific cell in table 2. neither cell has matching id or key.
UPDATE table1 SET column = (
SELECT column
FROM table2
WHERE id = key
)
WHERE id = key
//update cell value in table 1 with value from table 2 where a specific id/key matches
UPDATE table_1
SET column = table_2.column
FROM table_2
WHERE table_1.id = table_2.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment