How to use Distinct only in single Column, While you Getting Multiple Columns from Database.

Steps: Use this Query

SELECT * FROM (SELECT col1,col2, col3,col4, ROW_NUMBER() OVER (PARTITION BY (write here Distinct col name without brackets)  ORDER BY col1) AS RowNumber FROM  TableName) AS a WHERE  a.RowNumber = 1"

e.g.

SELECT * FROM (SELECT col1,col2, col3,col4, ROW_NUMBER() OVER (PARTITION BY col1   ORDER BY col1) AS RowNumber FROM  TableName) AS a WHERE  a.RowNumber = 1"

 
Here Row_Number() :

Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.
 

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now