The LIKE keyword is used to select those rows that match the specified portion of character string. The LIKE keyword allows for wildcard characters that can be used as an expression.
SQL LIKE Syntax:
SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern
Example:
SELECT * FROM Titles WHERE type LIKE 'bus%'
Returns all the rows from titles table in which the type of the book starts with the three character ‘bus’.
SELECT * FROM Publishers WHERE country LIKE 'US_'
Returns all the rows from the publishers table in which the country name is three characters long and start with ‘us’ whereas the third character can be anything.
SELECT * FROM Titles WHERE title_id LIKE 'P[SC]%'
Returns all the rows from the titles table in which title_id starts with the character P and contains a S or C in the second position, followed by any number of characters.
SELECT * FROM Titles WHERE title_id LIKE 'P[^C]%'
Returns all the rows from the titles table in which title_id starts with the character P and does not contains a C in the second position, followed by any number of characters.