Sql Tutorial Class


How to use in keyword in sql query

In keyword in SQL Query: It is used to display the selected record(s).


IN Keyword in SQL Server:
Syntax:
         Select [*|COLUMN_NAME,...] From [TABLE_NAME] Where IN('VALUE','VALUE2',...)

Description:
             Select: SQL Keyword.
             * | COLUMN_NMME: All or specific column name.
             From: SQL Keyword.
             TABLE_NAME: Name of table.
             Where: SQL keyword.
            [IN]: SQL Keyword.


Here is a Table ItemDetails
ItemCodeItemNameManufactureCompanyItemSerialNoItemCategoryItemQuantityItemPriceProductCountry
1Samsung MobileSamsungS12345Mobile500240Korea
2Samsung ProSamsungSP1234Mobile100300Korea
3Samsung HeadphoneSamsungSH2345Headphone5050Korea
4iPhoneiPoneiP12345Mobile1000500United Stat
5Apple MobileAppleA12345Mobile200300United Stat
6Apple ComputerAppleA12343Computer200400United Stat
7Apple MacbookAppleAM2345Macbook50600United Stat
8Dell ComputerDELLD02345Computer200240United Stat
9Dell LaptopDELLDL2345Laptop30240United Stat
10Apple LaptopAppleAL2345Laptop500100United Stat
11Apple HeadphoneAppleAH2345Headphone5020United Stat
12Sony CameraSonySN2345Camera200240Japan
13Sony HeadphoneSonySNH345Headphone50050Japan
14Ascer ComputerAscerAC2345Computer100600China
16Borother PrinterBrotherB12345Printer200200China
17Ascer PrinterAscerAP2345Printer200150China
18Brother PhotocopyBrotherBP2345Printer20150China
19Brother Multi PrinterBrotherBM243PhotocopyNULLNULLIndia



Now
Select ItemCode,ItemName,ManufactureCompany,ItemPrice from ItemDetails Where ManufactureCompany IN('Samsung','Apple','DELL')
Result:
ItemCode ItemName ManufactureCompany ItemPrice
1 Samsung Mobile Samsung 240
2 Samsung Pro Samsung 300
3 Samsung Headphone Samsung 50
5 Apple Mobile Apple 300
6 Apple Computer Apple 400
7 Apple Macbook Apple 600
8 Dell Computer DELL 240
9 Dell Laptop DELL 240
10 Apple Laptop Apple 100
11 Apple Headphone Apple 20




Select ItemCode,ItemName,ProductCountry from ItemDetails Where ItemCategory IN('Mobile','iPhone')

Result:


ItemCode ItemName ProductCountry
1 Samsung Mobile Korea
2 Samsung Pro Korea
4 iPhone United Stat
5 Apple Mobile United Stat


Select ItemCode,ItemName,ProductCountry,ProductCountry,ItemPrice from ItemDetails Where ItemPrice IN('500','600')
Result:
ItemCode ItemName ProductCountry ProductCountry2 ItemPrice
4 iPhone United Stat United Stat 500
7 Apple Macbook United Stat United Stat 600
14 Ascer Computer China China 600




SQL IN Keyword Example in Video





SQL IN Keyword Example in Image

How to use in keyword in sql server







No comments:

Post a Comment