MySQL IN Operators with WHERE Condition

We learn to mysql in operator, in subquery, in clause, in array, installer, like in mysql, between, not in with examples

MySQL IN() function

SELECT 
    branch_code, 
    area, 
    mobile, 
    place
FROM
    branchs
WHERE
    place IN ('INDIA' , 'JAPAN');

You can achieve the same result with the OR operator as the following query: MySQL WHERE Clause With AND, OR, IN, NOT IN

SELECT 
    branch_code, 
    area, 
    mobile
FROM
    branchs
WHERE
    place = 'INDIA' OR place = 'JAPAN';    

To get branchs that do not locate in INDIA and JAPAN, you use NOT IN in the WHERE clause as follows:

Read Also:  Laravel 5.8 Dropzone Multiple Image Upload

SELECT 
    branch_code, 
    area, 
    mobile
FROM
    branchs
WHERE
    place NOT IN ('INDIA' , 'JAPAN');

MySQL IN with a subquery

SELECT    
	stockNumber, 
	memberNumber, 
	is_check, 
	shippedDate
FROM    
	stocks
WHERE stockNumber IN
(
	 SELECT 
		 stockNumber
	 FROM 
		 stockDetails
	 GROUP BY 
		 stockNumber
	 HAVING SUM(qtyOrdered * amountEach) > 60000
);

First, the subquery returns a list of stock numbers whose values are greater than 60,000 using the GROUP BY and HAVING clauses:

SELECT 
    stockNumber
FROM
    stockDetails
GROUP BY 
    stockNumber
HAVING 
    SUM(qtyOrdered * amountEach) > 60000;

Second, the outer query uses the IN operator in the WHERE clause to get data from the stocks table:

Read Also:  Laravel 5.7 Route Group Names Example

SELECT 
    stockNumber, 
    memberNumber, 
    is_check, 
    shippedDate
FROM
    stocks
WHERE
    stockNumber IN (10165,10287,10310);

I hope you get an idea about MySQL IN() function.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.