SQL LIKE Keyword
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. It is commonly used with the following wildcards:
%
– represents zero, one, or multiple characters_
– represents a single character
SQL LIKE Syntax
SQL
x
1
SELECT column1, column2, ...
2
FROM table_name
3
WHERE column_name LIKE pattern;
SQL LIKE Patient Names Starting with “A” Example
This query selects all patients whose first_name starts with the letter “A”.
SQL
1
1
SELECT patient_id, first_name
2
FROM Patients
3
WHERE first_name LIKE 'A%';

SQL LIKE Patient Names Ending with “a” Example
This query selects all patients whose first_name ends with the letter “a”.
SQL
1
1
SELECT patient_id, first_name
2
FROM Patients
3
WHERE first_name LIKE '%a';

SQL LIKE Doctor Specialties Containing “gen” Example
This query selects all doctors whose specialty contains the substring “gen” if there is any.
SQL
1
1
SELECT doctor_id, specialty
2
FROM Doctors
3
WHERE specialty LIKE '%gen%';

SQL LIKE Patient Names with Pattern “J__n%” Example
This query selects all patients whose first names start with “J”, followed by any two characters, and then any number of characters.
SQL
1
1
SELECT patient_id, first_name
2
FROM Patients
3
WHERE first_name LIKE 'J__%';
