Showing posts with label REGEXP. Show all posts
Showing posts with label REGEXP. Show all posts
Thursday, March 26, 2020
Searching columns for patterns in MYSQL
There are many different ways to search a column for a pattern. You can use string functions and operators or regular expressions.
Below are some (not all) of the different ways to search a column with phone numbers that contain the sequential 415 number.
To find numbers starting with 415:
SELECT PhoneNumber FROM ContactInformation WHERE PhoneNumber LIKE '415%';
SELECT PhoneNumber FROM ContactInformation WHERE LEFT(PhoneNumber,3) = '415';
SELECT PhoneNumber FROM ContactInformation WHERE PhoneNumber REGEXP '^415';
SELECT PhoneNumber FROM ContactInformation WHERE SUBSTRING(PhoneNumber,1,3) = '415';
To find numbers containing 415 in the number:
SELECT PhoneNumber FROM ContactInformation WHERE PhoneNumber LIKE '%415%';
SELECT PhoneNumber FROM ContactInformation WHERE PhoneNumber REGEXP '415';
SELECT PhoneNumber FROM ContactInformation WHERE PhoneNumber REGEXP '415?';
Subscribe to:
Posts (Atom)
Percentage of Full Table Scans on MYSQL
Below is a useful script I use to determine what percentage of my queries in MYSQL are performing full table scans. Limiting full table sca...
-
I was recently asked to give a talk about database architecture to a group of DEVOPS and Site Reliability Engineers. So I wrote this BLOG p...
-
Below is a useful script I use to determine what percentage of my queries in MYSQL are performing full table scans. Limiting full table sca...
-
I always feel like I'm digging around to find a list of date formats for MYSQL. I then end up doing some trial and error to get the de...