postgresqlHow to use the NOT IN operator in PostgreSQL?
The NOT IN operator in PostgreSQL is used to test if a value is not present in a list of values. This operator is used in the WHERE clause of a SELECT, UPDATE, or DELETE statement.
For example, if you want to select all customers who are not in the list of specified cities, you could use the following code:
SELECT *
FROM customers
WHERE city NOT IN ('New York', 'Los Angeles', 'Chicago');
This statement will return all customers who are not from the cities of New York, Los Angeles, or Chicago.
The parts of the code are:
SELECT *
- This statement is used to select all columns from the customers table.FROM customers
- This statement specifies the table from which to select the data.WHERE city NOT IN ('New York', 'Los Angeles', 'Chicago')
- This statement is used to filter out all customers who are not from the specified cities.
Helpful links
More of Postgresql
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL and ZFS together?
- How do I set the PostgreSQL work_mem parameter?
- How can I use PostgreSQL with YAML?
See more codes...