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
SELECT column1, column2, ... FROM table_name 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”.
SELECT patient_id, first_name FROM Patients 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”.
SELECT patient_id, first_name FROM Patients 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.
SELECT doctor_id, specialty FROM Doctors 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.
SELECT patient_id, first_name FROM Patients WHERE first_name LIKE 'J__%';
