The SQL IN clause allows you to specify discrete values in your SQL WHERE search criteria.
THE SQL IN syntax looks like this:
SELECT Column1, Column2, Column3, …
FROM Table1
WHERE Column1 IN (Valu1, Value2, …)
Lets use the EmployeeHours table to illustrate how SQL IN works:
Employee Date Hours
John Smith 5/6/2004 8
Allan Babel 5/6/2004 8
Tina Crown 5/6/2004 8
John Smith 5/7/2004 9
Allan Babel 5/7/2004 8
Tina Crown 5/7/2004 10
John Smith 5/8/2004 8
Allan Babel 5/8/2004 8
Tina Crown 5/8/2004 9
Consider the following SQL query using the SQL IN clause:
SELECT *
FROM EmployeeHours
WHERE Date IN ('5/6/2004', '5/7/2004')
This SQL expression will select only the entries where the column Date has value of '5/6/2004' or '5/7/2004', and you can see the result below:
Employee Date Hours
John Smith 5/6/2004 8
Allan Babel 5/6/2004 8
Tina Crown 5/6/2004 8
John Smith 5/7/2004 9
Allan Babel 5/7/2004 8
Tina Crown 5/7/2004 10
We can use the SQL IN statement with another column in our EmployeeHours table:
SELECT *
FROM EmployeeHours
WHERE Hours IN (9, 10)
The result of the SQL query above will be:
Employee Date Hours
John Smith 5/7/2004 9
Tina Crown 5/7/2004 10
Tina Crown 5/8/2004 9
Popular Posts
-
Arguments passed by value and by reference. Until now, in all the functions we have seen, the arguments passed to the functions have been pa...
-
SQL Server Express is a free, easy to use, redistributable version of SQL Server 2005 designed for building simple data-driven applications....
-
Declaration of variables In order to use a variable in C++, we must first declare it specifying which data type we want it to be. The syntax...
-
Syntax of JSP Scriptles are: <% //java codes %> JSP Scriptlets begins with <% and ends %> .We can embed any a...
-
The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s). For example if you want to select all t...
-
STRINGS: The way a group of integers can be stored in an integer array, similarly a group of characters can be stored in a character array. ...
-
Java Server Pages JavaServer Pages (JSP) technology is the Java platform technology for delivering dynamic content to web clients in a por...
-
DIFFERENCE BETWEEN STRUCT AND UNION: In structures,each member has its own storage location,whereas all memebers of a union use the same loc...
-
SQL is short for Structured Query Language and is a widely used database language, providing means of data manipulation (store, retrieve, up...
-
Inheritance A key feature of OOP is reusability. It's always time saving and useful if we can reuse something that already exists rather...
No comments:
Post a Comment