xxxxxxxxxx
SELECT first_name, country
FROM Customers
WHERE country IN ('USA', 'UK');
xxxxxxxxxx
Used alongside a WHERE clause as a shorthand for multiple OR conditions.
So instead of:
SELECT * FROM users
WHERE country = 'USA' OR country = 'United Kingdom' OR
country = 'Russia' OR country = 'Australia';
You can use:
SELECT * FROM users
WHERE country IN ('USA', 'United Kingdom', 'Russia',
'Australia');
xxxxxxxxxx
= Checks if the values of two operands are equal or not, if yes then condition becomes true. (a = b) is not true.
!= Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (a != b) is true.
<> Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (a > b) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (a < b) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.
!< Checks if the value of left operand is not less than the value of right operand, if yes then condition becomes true. (a !< b) is false.
!> Checks if the value of left operand is not greater than the value of right operand, if yes then condition becomes true. (a !> b) is true.
xxxxxxxxxx
-- IN is a shortcut of OR for a list of values that exist in same column
SELECT col1, col2
FROM table_name
WHERE col2 = 'A' AND (col1 = 1920 OR col1 = 1930 OR col1 = 1940);
-- Now since col1 has multiple values with OR, we can replace these OR with IN
SELECT col1, col2
FROM table_name
WHERE col2 = 'A' AND col1 IN (1920, 1930, 1940);
xxxxxxxxxx
(IN) operator in sql like "OR" operator
For example:
Select * From employees
Where department_id "IN" (60,90);
xxxxxxxxxx
SELECT EmpId FROM EmployeeDetails
UNION
SELECT EmpId FROM EmployeeSalary;
xxxxxxxxxx
SELECT EmpId,
Salary+Variable as TotalSalary
FROM EmployeeSalary;
xxxxxxxxxx
SELECT column1, column2,
FROM table_name
WHERE column_name IN (value1, value2, );
xxxxxxxxxx
(IN) operator in sql like "OR" operator
For example:
Select * From employees
Where department_id "IN" (60,90);
xxxxxxxxxx
SELECT FullName
FROM EmployeeDetails
WHERE FullName LIKE ‘__hn%’;