Sql Tutorial Class


How to use distinct keyword in sql server

Distinct keyword in SQL Server: Distinct keyword display the unique record from SQL Server table. It removes duplicate value(s) and display unique value(s).

SQL Server distinct keyword syntax, without SQL select where statement:

Select distinct COLUMN_NAME From TABLE_NAME

SQL Server distinct keyword syntax, with SQL select where command:
Select distinct COLUMN_NAME From TABLE_NAME Where [COLUMN_NAME]=['VALUE']

Description:
             Select: SQL Keyword.
             distinct: SQL keyword.             
        COLUMN_NMME: Column name.
             From: SQL Keyword.
             TABLE_NAME: Name of table.
             Where: SQL keyword.
            ['VALUE'] : User defined value.



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 distinct ItemCategory from ItemDetails
Result:
ItemCategory
Camera
Computer
Headphone
Laptop
Macbook
Mobile
Photocopy
Printer


Select distinct ManufactureCompany from ItemDetails
Result:
ManufactureCompany
Apple
Ascer
Brother
DELL
iPone
Samsung
Sony




Select distinct ItemCategory from ItemDetails where ProductCountry='United Stat'
Result:
ItemCategory
Computer
Headphone
Laptop
Macbook
Mobile





Distinct keyword in video






Distinct keyword in Image
How to use distinct keyword in sql server




No comments:

Post a Comment