Saturday, February 20, 2021

HOW TO USE DISTINCT WITH SELECT STATEMENT IN SQL SERVER

DISTINCT:- The DISTINCT keyword is used to fetch or get the unique records from the table with select statement. It eliminates or remove duplicates records and fetch only unique records from table. 

The syntax of DISTINCT keyword is used with Select Statement is as below:

SELECT DISTINCT  COLUMN1 FROM TABLE

Here, we have a table i.e. PRODUCTS with list of 15 records in TESTDB. Please see the below screenshot:

SELECT * PRODUCT_NAME FROM PRODUCTS



Now, we are using the DISTINCT keyword with Select statement to get or fetch the unique or different Product names from Products table with the below query.

SELECT DISTINCT PRODUCT_NAME FROM PRODUCTS

Here is an example of DISTINCT with Select Statement. Please see the attachment file as below:




   - - - - - - Cheers, Happy to Help! - - - - - - 

DIFFERENCE BETWEEN CHAR AND VARCHAR IN SQL SERVER

CHAR:  The  CHAR datatype is a fixed length data type in sql server. It is used to store fixed length type of string data or character strin...