PostgreSQL - NOT LIKE operator Last Updated : 11 Oct, 2024 Comments Improve Suggest changes Like Article Like Report 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 OperatorThe NOT LIKE operator is used in SQL queries to filter out rows that do not match a specific pattern. It is especially useful when we need to eliminate certain string patterns from our results. This operator is part of PostgreSQLs string comparison toolkit and can work with other PostgreSQL window functions or conditional operators. Syntax:SELECT column1, column2, ...FROM table_nameWHERE column_name NOT LIKE pattern;Explanation:column_name: The column to filter.pattern: The string pattern, with wildcards (% for multiple characters and _ for a single character) to match against.Examples of NOT LIKE operatorExample 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_nameFROM customerWHERE first_name NOT LIKE 'K%';Output:Explanation: In this SQL query, we use the SELECTstatement to specify the columns first_name and last_name we want to retrieve from the customer table.The WHERE clause filters the results to exclude any records where the first_name begins with 'K', indicated by the NOT LIKE 'K%' condition. The percentage symbol (%) is a wildcard in SQL that represents zero or more characters, meaning any first name starting with 'K' will not be included in the result set. Example 2: Let's write an query is to retrieve the first and last names of customers from the customertable whose first names do not contain the substring "her" at the second position.SELECT first_name, last_nameFROM customerWHERE first_name NOT LIKE '_her%';Output: Explanation: This SQL query retrieves the `first_name` and `last_name` of customers from the `customer` table whose first names do not have the substring "her" starting from the second position. The `NOT LIKE '_her%'` condition uses the underscore (`_`) wildcard to represent any single character before "her," ensuring that only names that do not fit this pattern are returned.ConclusionIn 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. Comment More infoAdvertise with us Next Article PostgreSQL - NOT LIKE operator R RajuKumar19 Follow Improve Article Tags : Python PostgreSQL Databases postgreSQL-operators Practice Tags : python Similar Reads PostgreSQL - NOT IN operator PostgreSQL NOT IN condition is a powerful tool for data retrieval in PostgreSQL by allowing users to filter out specific values from their query results. This condition is particularly useful when we want to exclude a defined set of values from a dataset by making our queries more efficient and targ 4 min read PostgreSQL - LIKE operator In PostgreSQL, the LIKE operator is an essential tool for pattern matching in SQL queries. Whether we're dealing with large datasets or searching for specific string patterns, this operator provides a powerful way to filter and retrieve data based on partial matches. By Using wildcard search techniq 5 min read PostgreSQL - IN operator The IN operator in PostgreSQL is a powerful and efficient tool used to filter records based on a predefined set of values. When used with the WHERE clause, it simplifies SQL queries and enhances readability, making it a key component of SQL query optimization for data retrieval and database manipula 4 min read PostgreSQL - NOT BETWEEN operator PostgreSQL NOT BETWEEN operator is used to match all values against a range of values excluding the values in the mentioned range itself. Syntax: value NOT BETWEEN low AND high; Or, Syntax: value high; The NOT BETWEEN operator is used generally with WHERE clause with association with SELECT, INSERT, 1 min read PostgreSQL - IS NULL operator The PostgreSQL IS NULL operator is used to check whether a value is NULL. In the context of databases, NULL indicates that data is either missing or not applicable. Since NULL cannot be compared directly with any integer or string (as such comparisons result in NULL, meaning an unknown result), the 2 min read PostgreSQL - ANY Operator The ANY operator in PostgreSQL is a powerful tool for comparing a scalar value against a set of values returned by a subquery. From this article, we can better understand the ANY Operator in PostgreSQL.Syntaxexpression operator ANY(subquery)Rules of ANY Operator The below rules must be followed whil 3 min read PostgreSQL - ALL Operator The PostgreSQL ALL operator is a powerful tool for comparing a value with a list of values returned by a subquery. This operator is essential for filtering and querying data based on comparisons with multiple values, making it a valuable addition to any PostgreSQL user's toolkit.Let us better unders 3 min read PostgreSQL - EXCEPT Operator In PostgreSQL, the EXCEPT operator is a powerful tool used to return distinct rows from the first query that are not present in the output of the second query. This operator is useful when you need to compare result sets of two or more queries and find the differences.Let us better understand the EX 3 min read PostgreSQL - EXISTS Operator The EXISTS operator in PostgreSQL is a powerful SQL feature used to check the existence of rows in a subquery. It is particularly useful when working with correlated subqueries, where the inner query depends on values from the outer query. The EXISTS operator returns true if the subquery returns at 4 min read PostgreSQL - BETWEEN Operator The PostgreSQL BETWEEN operator is an essential tool for filtering data within a specific range. Often used in the WHERE clause of SELECT, INSERT, UPDATE, and DELETE statements, this operator simplifies range-based conditions, making queries faster and easier to read. In this article, we will explai 3 min read Like