PostgreSQL NOT LIKE operator (original) (raw)

Last Updated : 12 Jul, 2025

The **PostgreSQL NOT LIKE operator is a powerful tool used in **SQL queries to filter out rows that do not match specific patterns. By utilizing this operator, users can eliminate undesired string patterns from their results, enabling more precise **data retrieval.

It is particularly beneficial in scenarios where specific naming conventions or formats need to be excluded. In this article, We will learn about the **PostgreSQL NOT LIKEOperator by understanding various examples and so on.

PostgreSQL NOT LIKE Operator

**Syntax:

SELECT column1, column2, ...
FROM table_name
WHERE column_name NOT LIKE pattern;

**Explanation:

Examples of NOT LIKE operator

**Example 1:

Let's write an query is to retrieve the first and last names of customers from the customer table whose first names do not start with the letter 'K'.

SELECT
first_name,
last_name
FROM
customer
WHERE
first_name NOT LIKE 'K%';

**Output:

**Explanation:

**Example 2:

Let's write an query is to retrieve the **first and **last names of **customers from the **customer**table whose first names do not contain the substring "her" at the second position.

SELECT
first_name,
last_name
FROM
customer
WHERE
first_name NOT LIKE '_her%';

**Output:

exam2

**Explanation:

Conclusion

In summary, the **NOT LIKE operator in PostgreSQL provides an effective means to refine query results by excluding unwanted patterns. Whether you need to filter out names based on their initial letters or exclude specific substrings, this operator simplifies the process.