Merging two rows to one while replacing null values

后端 未结 2 1420
不思量自难忘°
不思量自难忘° 2020-12-15 23:20

Let\'s say I\'ve got the following database table

Name | Nickname | ID
----------------------
Joe    Joey       14
Joe    null       14

Now

2条回答
  •  伪装坚强ぢ
    2020-12-15 23:58

    AFAIK, the question is not clear.so i am making some assumptions over here. your output has the first and 3rd columns for both the rows as same. Only the 2nd field is different.

    so u can simply write a select quest

    select one.name,two.nick_name,one.id from 
    (select name,id from your_tb group by name,id) one,
    your_tb two 
    where two.nickname is not NULL 
    and two.name=one.name 
    and two.id=one.id;
    

    may be we can tune this but i am not good in tuning sql squeries,but this is the way i suppose u need.

提交回复
热议问题