SQL Server - how to select record based on distinct one column ?
Asked By mani on 29-Mar-12 05:43 AM
hi...i have sareenumber with multiple duplicate value in my table...and i need select record based on distinct sareenumber..
kalpana aparnathi replied to mani on 29-Mar-12 05:51 AM
Using this for getting records,
Sandeep Mittal replied to mani on 29-Mar-12 05:51 AM
Please elaborate your requirement bit more clearly.
mani replied to Sandeep Mittal on 29-Mar-12 05:57 AM
i have saree number with duplicate values and i need to select record with distinct row based on sareenumber only..so i need to avoid duplicate record with sareenumber
Somesh Yadav replied to mani on 29-Mar-12 06:06 AM
a similar example is explained here,
Hope it helps you.
Sandeep Mittal replied to mani on 29-Mar-12 06:07 AM
If you have different values in other columns for sareenumber, then you would not be able to get the distinct data of sareenumber using select *.
Distinct operator works on all columns used in select. if the whole row data is same then only it would give a single row for duplicate rows.
Post some sample data and desired output.
Pat Hartman replied to mani on 29-Mar-12 12:18 PM
If you have no unique identifier, how would you propose that the query decide which non-unique row to return? One possibility is the Top values predicate.
Select Top 1 yourtable.*
Where somefield = somevalue;