The NOT IN operator in SQL


In addition to commands, clauses, SQL uses many different operators. In this article, Taimienphi.vn will introduce you to the NOT IN operator in SQL. There are also comparison operators like LIKE, IN, IS NULL, BETWEEN, AND, …


The NOT IN operator in SQL This is used when you want to retrieve columns that do not contain table or reference tables. The NOT IN operator in SQL is quite important, especially if you are searching for keywords.

For example, in case you need to find answers to questions:

– Which customers do not make transactions with the store?
– What products have not been sold in the last few days?

Example of NOT IN operator in SQL

For example, if you want to search for the name of a customer who has not made a transaction with you yet

Below is the customer table that contains a record of all customers and the transaction table containing transaction information between the store and customers.

The customer table contains customer records:

not print in sql 2

The transaction table contains the transaction information:

not print in sql 3

The NOT IN statement in SQL is written as follows:

Select first_name, last_name, cust_id from customer where cust_id NOT IN (Select cust_id from transactions)

Output:

not print in sql 4

This is the name of 2 customers who have not made transactions.

https://thuthuat.taimienphi.vn/not-in-trong-sql-33279n.aspx
Above is some information, examples of NOT IN operator in SQL. In the next article, Taimienphi.vn will introduce you to comparison operators in SQL, including LIKE, IN, IS NULL, BETWEEN … AND. In addition, readers can refer to some articles about CREAT, UPDATE, DELETE … statements in SQL on Taimienphi.vn for more information. Do not forget to find out about SQL What is and share your opinions, reviews for Taimienphi.vn offline.

.

Add a Comment

Your email address will not be published. Required fields are marked *