Hi Boris,
It’s a bit of a ‘weird’ way of making something like that, but:
If you P > Separate > by Loose Parts, you can Switch to Object Mode and then use a Boolean Union to combine the twq and get something like the Mesh on the left:

Subdividing the 2 long Edges on the top of the top cube gives you some extra Vertices, that you can connect down with J, to get an all-quad Topology..
A lot easier would be to start with the top cube, CTRL+R to make 2 Loop Cuts and then Extrude the middle Face at the Bottom down. Something like this:
