The Mysql-LIKE Operator
MySQL LIKE operator checks whether a specific character string matches a specified pattern. ... % is used to match any number of characters,
frequently I used this operator whenever I try to find something in my database i'll use this and get that result it's very useful for me.
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE operator:
The percent sign (%) represents zero, one, or multiple characters The underscore sign (_) represents one, the single character
LIKE Operator
SELECT * FROM YOUR_TABLE WHERE COLUMN_NAME LIKE 'a%'
here Find any values that start with "a"
after executing this query fetches data like this
- ahjk
- asd
- akl
- asdf
- aghjkl
- aaaa
same as like but before putting the % Finds any values that end with "a"
SELECT * FROM YOUR_TABLE WHERE COLUMN_NAME LIKE '%a'
example
- hjkaa
- qwertyaaa
- werthyjkaa
- oiuyaaa
- twerta
- lkja
Finds any values that have "or" in any position
SELECT * FROM YOUR_TABLE WHERE COLUMN_NAME LIKE '%or%'
here wherever data have or it's fetching
Finds any values that have "r" in the second position
SELECT * FROM YOUR_TABLE WHERE COLUMN_NAME LIKE '%_r%'
this like %_r% fetches data at the second position
Finds any values that start with "a" and are at least 2 characters in length
SELECT * FROM YOUR_TABLE WHERE COLUMN_NAME LIKE '%_r%'
Finds any values that start with "a" and are at least 3 characters in length
WHERE CustomerName LIKE 'a__%'
Finds any values that start with "a" and end with "o"
WHERE ContactName LIKE 'a%o'
That's all folks!