select min(id), dat1 from table where dat1 is not null group by dat1
union
select id , dat from table where dat1 is null
select min(id), dat1 from table where dat1 is not null group by dat1
union
select id , dat from table where dat1 is null