I am trying to replicate a table produced from a sybase database, I dont have the code but have access to the database.
I have reproduced the table almost perfectly, but because I used a union I have duplicate rows where they should have merged:
select distinct id, dn, pn, null as sp
from dn
union
select id, 'DN', 'PN', sp
from sp
order by id
But I produce, for example:
pn, dn, pn, sp
'110','Liversage','Consultant', null
'110','DN ','PN ','Cardiac'
Basically I wanted the null to be filled with cardiac and the DN and PN and row two to be merged into row one?
Why not do something like this:
Which will pick the first non-null value from each table. I have limited knowledge of your tables to give a complete answer, but you’re likely to have better luck with this approach as union doesn’t do what you seem to want it to do.