sql server - Select first duplicate in aliased field SQL -
i have sql query uses case .. when statement creates aliased field based upon values of other fields.
select id, case when len(lastname) = 0 firstname end displayname mytable
the resultant select statement contains "duplicates" alias displayname
. understand not duplicates because id field unique. how go obtaining distinct list of displayname
if don't care id associated it? cannot use displayname
alias in group by
statement because of order of logical operator precedence.
update - should have mentioned need id back, however, long id associated 1 of duplicates (first, last, etc ..)
select max(id) [id], displayname ( select id, case when len(lastname) = 0 firstname end displayname mytable ) group displayname
Comments
Post a Comment