Sealing the roof to the walls

I have been searching around the forum and this topic eludes me a bit. How does one go about making a water tight connection between the roof and the walls. I see in builds some sort of moulding appears to be used. But what type and how it is all done I don't really know.
Maybe there is links to enlighten me?
Maybe there is links to enlighten me?