Skip to content

Instantly share code, notes, and snippets.

@yohangdev
Created September 8, 2020 14:09
Show Gist options
  • Save yohangdev/796beabfb7a00e1c3940743a54381460 to your computer and use it in GitHub Desktop.
Save yohangdev/796beabfb7a00e1c3940743a54381460 to your computer and use it in GitHub Desktop.
Cheatsheet for common data cleansing with mySQL (Phone Number, NIK, dsb)
SELECT * FROM table WHERE phone_number REGEXP '^\\+62';
UPDATE table
SET phone_number = REPLACE(phone_number, '+62', '0')
WHERE phone_number REGEXP '^\\+62';
#######
SELECT * FROM table WHERE phone_number REGEXP '-';
UPDATE table
SET phone_number = REPLACE(phone_number, '-', '')
WHERE phone_number REGEXP '-';
#######
SELECT * FROM table WHERE nik REGEXP ' ';
UPDATE table
SET nik = REPLACE(nik, ' ', '')
WHERE nik REGEXP ' ';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment