SQL LIKE
The SQL LIKE operator is used in a WHERE clause to look for a particular pattern in a column.
Examples of SQL LIKE
Now we want to select the employees which have their names starting with "s".
SELECT * FROM employees
WHERE ename LIKE 's%'
We want to select the employees which have their names ending with "s".
SELECT * FROM employees
WHERE ename LIKE '%s'
We are looking for all employees whose name contains the characters 'sam'
SELECT * FROM employees
WHERE ename LIKE '%sam%'
This SQL statement would return all employees whose name is 5 characters long, where the first two characters is 'Sm' and the last two characters is 'th'. For example, 'Smith', 'Smyth', 'Smath', 'Smeth', etc.
SELECT * FROM employees
WHERE ename like 'Sm_th';
No comments:
Post a Comment