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

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -