Skip to content
UniCircle
EasySQLPattern matching

Case-insensitive name search with ILIKE

Question SQL-LIK-102

Table students(id int primary key, name text, branch text, cgpa numeric(3,1)).

A search box should find every student whose name contains the letters "ar" anywhere, ignoring case — "ARNAV", "Tara" and "Sharma" all match. Return id and name, ordered by id.

Constraints

  • Write one SELECT statement for PostgreSQL 16.
  • Output columns and row order must match exactly.

Input and output

Input
The setup script in the test case creates and fills the tables described above.
Output
Columns: id, name.

Example

Input

create table students (id int primary key, name text not null, branch text not null, cgpa numeric(3,1) not null);
insert into students values (1,'Arjun Rao','CSE',8.2),(2,'Diya Iyer','ECE',7.4),(3,'Tara Gill','ME',9.0),(4,'Kavya Sharma','CE',6.8),(5,'Dev Nair','CSE',7.0);

Output

1|Arjun Rao
3|Tara Gill
4|Kavya Sharma

"Arjun" starts with "Ar", "Tara" and "Sharma" contain "ar"; "Nair" has "ai", not "ar".

Show hints
  • % matches any run of characters.
  • PostgreSQL's ILIKE is LIKE without case sensitivity.
Show the explanation

name ILIKE '%ar%' matches "ar" at any position in any case. ILIKE is a PostgreSQL extension; the portable form is lower(name) LIKE '%ar%'. Note that a leading % stops an ordinary B-tree index from being used, so on a large table this scans every row (a trigram index can help).

Original UniCircle question. Last reviewed 22 Oct 2026.