SQL - SELECT MAX() and accompanying field

后端 未结 4 646
终归单人心
终归单人心 2020-12-31 23:41

What I have is basically a problem which is easily solved with multiple tables, but I have only a single table to do it.

Consider the following database table

<
4条回答
  •  春和景丽
    2021-01-01 00:08

    select distinct
         *  
    from    
       SomeTable a
    inner join (
      select max(emailAddress), userId
      from
         SomeTable 
      group by 
         userId
    ) b on a.emailAddress = b.emailAddress and a.userId = b.userId
    

提交回复
热议问题