Reputation: 33
I have a table where data are stocked like this :
student| first_name | last_name | age |
------------------------------------------------
A | ALEX | NULL | NULL | NULL |
A | NULL | BEN | NULL | NULL |
A | NUL | NULL | NULL | 10 |
B | SAM | NULL | NULL | NULL |
B | NULL | NULL | NULL | 15 |
Is there a way in SQL Server to get data like this :
student| first_name| last_name | age |
------------------------------------------------
A | ALEX | BEN | 10 |
B | SAM | NULL | 15 |
Upvotes: 2
Views: 57
Reputation: 35623
use group by
, on the common column(s), and max()
for columns with just one value per common column(s)
select student, max(first_name) first_name, max(last_name) last_name, max(age) age
from yourtable
group by student
Upvotes: 3