PostgreSQL – LIKE operator

LIKE operator is used to find strings with matching pattern. ‘%’ is used to match any number of characters and ‘_’ is used to match exactly 1 character.

Example, Below sql returns all employees whose names start with letter ‘A’.

SELECT name FROM employee WHERE upper(name) like 'A%';

Below sql returns all employees whose names start with letter ‘A’ and end with letter ‘I’.

SELECT name FROM employee WHERE upper(name) like 'A%I';

Below sql returns all employee names with the second from last letter as ‘A’.

SELECT name FROM employee WHERE upper(name) like '%A_';
See also  PostgreSQL - FROM Clause