|
SQL Home
SQL TutorialIntroductionSQL Syntax SQL Select SQL Where SQL Order By SQL Top SQL Distinct SQL In SQL Alias SQL Join SQL Inner Join SQL Outer Join SQL Insert SQL Update SQL Delete SQL Functions SQL Count SQL Create SQL Create Database SQL Create Table SQL Create Index SQL Alter Table SQL Summary FREE Hosting!With every domain name you register with ZappyHost, you get FREE hosting.$1.99 Domain NamesWith every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99. |
SQL InThe SQL IN operator assists you in providing multiple values in your WHERE clause. This can provide very useful when you need to compare your value to a list of values. Often this list could be the result of a query from another table. SQL Syntax
ExampleSQL statement
Source Table
Result
You might have noticed that this returns the same result as the following SQL statement:
Yes, we could just have easily used that statement but the SQL IN statement is more concise. SQL IN and SubqueriesNow, where the SQL IN operator becomes really useful is when you need to compare a value against the result of another query. For example, lets say we have another table called "Publisher". This table contains users who are allowed to contribute to the website via an administration console. All users in the Publisher table are also in the Individual table, but not all users in the Individual table are in the Publisher table. Source TablesIndividual Table
Publisher Table
Our task is to return a list of usernames from all publishers who have an access level of "Contributor". You may notice that the usernames are in the Individual table but the access level is stored in the Publisher table. Also, there could potentially be many contributors. This is a good candidate for the SQL IN operator! SQL statement
Result
In this example there aren't many records in the Publisher table, but imagine if there were thousands - the IN statement is great for this sort of thing. Enjoy this website?
Oh, and thank you for supporting Quackit! |
Need Content for your Website?Get unique, quality digital content for your website. You can even earn money by reselling it!Includes:
|