SQL

Perform Case-Insensitive Keyword Search

Implement a basic case-insensitive keyword search in your SQL database using the LOWER function with LIKE (SQL Standard) or ILIKE (PostgreSQL).

SELECT id, title, content
FROM posts
WHERE LOWER(title) LIKE LOWER('%keyword%') OR LOWER(content) LIKE LOWER('%keyword%');
-- In PostgreSQL, you can use ILIKE for more concise case-insensitive matching:
-- SELECT id, title, content FROM posts WHERE title ILIKE '%keyword%' OR content ILIKE '%keyword%';
How it works: This query performs a basic case-insensitive keyword search across the `title` and `content` columns in the `posts` table. By converting both the column content and the search term to lowercase using `LOWER()`, it ensures that 'Keyword', 'keyword', and 'KEYWORD' all yield the same results. PostgreSQL users can simplify this with the `ILIKE` operator, which natively handles case-insensitivity.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs