Use of IN operator in SQL:
(1) “IN” operator is used where multiple conditions are executed. It is a shortcut of the “OR” operator. It is used with the “WHERE” clause.
(2) Syntax of “IN” statement is:
SELECT column1, column2, … FROM table_name WHERE column1 IN (value1,value2… valueN); |
(3) Let’s take an example to get records according to the “Country Region Code” columns are equal to the assigned values as shown.
(4) Select the database in the SQL server and click on the “New Query” button as shown.
(5) After that new query editor open as shown.
(6) After doing the above steps, write a query in the editor, as shown.
Source Code:
–// Without “IN” operator in Vendor table Select [No_],[Name],[Address],[Country_Region Code] from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972] –// Without “IN” operator in Vendor table –// With “IN” operator in Vendor table Select [No_],[Name],[Address],[Country_Region Code] from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972] where [Country_Region Code] IN (‘IN’,’CA’) –// With “IN” operator in Vendor table |
(7) After writing the query, then execute the query (Shortcut keys is F5) as shown.
(8) After executing the two queries in the same editor, SQL gives two results. Note: Recommended write and execute query one by one for reporting.