The MySQL IN Operator The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.
customer_id = order_details. customer_id ORDER BY order_id; This MySQL FROM clause example uses the FROM clause to list two tables - customers and order_details. And we are using the FROM clause to specify an INNER JOIN between the customers and order_details tables based on the customer_id column in both tables.
In SQL, BETWEEN is a logical operator used to select a range of values from the table of the database. Using the between the query, we can also check whether a value is in the provided range or not. BETWEEN in MySQL is generally used with the SELECT statements, and with INSERT, DELETE, and UPDATE queries.
Today I have posted an answer with a query like this
SELECT * FROM table_name where column_name IN (val1,val2,...)
Some another user has posted the answer a query like this
SELECT * FROM table_name where val1 IN (column_name)
As you can see here the position of the column_name and values are interchanged.
expr IN (value,...)
Returns 1 if expr is equal to any of the values in the IN list, else returns 0. If all values are constants, they are evaluated according to the type of expr and sorted. The search for the item then is done using a binary search. This means IN is very quick if the IN value list consists entirely of constants.
mysql> SELECT 2 IN (0,3,5,7);
-> 0
mysql> SELECT 'wefwf' IN ('wee','wefwf','weg');
-> 1
As it clearly says that the above one(my query) is correct. but both the above queries produce the same output.
Also why not the other approach in listed in Mysql Documentation?
This question serves as a canonical information source regarding the use of IN. Its purpose is to have detailed, high quality answers detailing the proper use on IN in queries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With