Sql Tutorial Class


How to use between in sql query

Between operator in SQL Server: It is used to display record(s) on range. 

Between Operator in SQL Server:

Syntax:
         Select [*|COLUMN_NAME,...] From [TABLE_NAME] Where COLUMN_NAME BETWEEN 'VALUE' AND 'VALUE2'

Description:
             Select: SQL Keyword.
             * | COLUMN_NMME: All or specific column name.
             From: SQL Keyword.
             TABLE_NAME: Name of table.
             Where: SQL keyword.
             AND: SQL operator.
             VALUE.. : User define value.           
           [BETWEEN]: SQL operator.


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 ItemName,ManufactureCompany,ItemCategory,ItemPrice from ItemDetails Where ItemPrice between '200' and '500'
Result:
ItemName ManufactureCompany ItemCategory ItemPrice
Samsung Mobile Samsung Mobile 240
Samsung Pro Samsung Mobile 300
iPhone iPone Mobile 500
Apple Mobile Apple Mobile 300
Apple Computer Apple Computer 400
Dell Computer DELL Computer 240
Dell Laptop DELL Laptop 240
Sony Camera Sony Camera 240
Borother Printer Brother Printer 200








Select ItemName,ManufactureCompany,ItemCategory,ItemQuantity from ItemDetails where ItemQuantity Between '200' and '500'
Result:
ItemName ManufactureCompany ItemCategory ItemQuantity
Samsung Mobile Samsung Mobile 500
Apple Mobile Apple Mobile 200
Apple Computer Apple Computer 200
Dell Computer DELL Computer 200
Apple Laptop Apple Laptop 500
Sony Camera Sony Camera 200
Sony Headphone Sony Headphone 500
Borother Printer Brother Printer 200
Ascer Printer Ascer Printer 200





Between operator in SQL Server




Between operator in SQL Server
How to use between operator inSQL Server





No comments:

Post a Comment