The SQL IN operator providing multiple values in your WHERE clause.
This can provide very useful when you need to compare your value to a list of values.
Syntax-
SELECT * FROM table_name WHERE column_name IN (value1,value2,...)
Source Table - Master
Id FirstName LastName
1 Fred Jeddo
2 Tomer homey
3 Homer Lacto
4 Ozzy dev
5 mer Kumar
SELECT * FROM Master
WHERE LastName IN ('homey','dev','Kumar');
Result table-
Id FirstName LastName
2 Tomer homey
4 Ozzy dev
5 mer Kumar
You might have noticed that this returns the same result as the following SQL statement:
SELECT * FROM Individual
WHERE LastName = 'honey'
OR LastName = 'dev'
OR LastName = 'kumar';
This can provide very useful when you need to compare your value to a list of values.
Syntax-
SELECT * FROM table_name WHERE column_name IN (value1,value2,...)
Source Table - Master
Id FirstName LastName
1 Fred Jeddo
2 Tomer homey
3 Homer Lacto
4 Ozzy dev
5 mer Kumar
SELECT * FROM Master
WHERE LastName IN ('homey','dev','Kumar');
Result table-
Id FirstName LastName
2 Tomer homey
4 Ozzy dev
5 mer Kumar
You might have noticed that this returns the same result as the following SQL statement:
SELECT * FROM Individual
WHERE LastName = 'honey'
OR LastName = 'dev'
OR LastName = 'kumar';
0 comments:
Post a Comment