+ 3
What's the best example for **IN** logical operator.
I need more example and Definition for **IN** logical operators.
2 Answers
+ 6
I am going to explain you comparing two SQL Scripts, one is using OR operator and the other one using IN operator.
The OR operator displays a record if either the first condition or the second condition is true. e.g:
SELECT * FROM customers
WHERE City='New York' OR City='Los Angeles' OR City='Chicago';
The IN operator allows you to specify multiple values in a WHERE clause. We can also says that IN operator return TRUE if the operand is equal to one of a list of expressions. e.g.:
SELECT * FROM customers
WHERE City IN ('New York', 'Los Angeles', 'Chicago');
Both queries return the same result set. Both are going to retrieve data where cities are New York, Los Angeles, Chicago. Only if the data satisfy the condition, otherwise the data will not be retrieved. Let's say we have values on Boston, those values do not satisfy the condition thus is not going to be retrieved.
+ 1
Let's say you want records that meet a specific X number of conditions.
For example,
SELECT NAME, Age
FROM Person
WHERE NAME IN ('Jesus','Jose','Rikesh')
Will return only the records which meet that criteria. (Records with the NAME equal to Jesus, Jose, and Rikesh)