What is the exact relationship? The history as I remember it is:
1. SGML (Simple Generalised Markup Language) came first.
2. HTML was a specialisation of SGML, it took off because of the web, and is probably the only reason for SGML to become famous.
3. XML was then invented as a generalisation of HTML, perhaps by people who had never heard of SGML.
And I seem to remember DocBook is an SGML thing, it was invented between steps 2 and 3.
That's completely wrong. XML is specified as a subset of SGML (it says so in the preamble even) by folks who where also involved in specifying SGML. Moreover, these same folks (the "Extended Review Board" at W3C) also amended SGML to align with the XML profile of SGML in ISO 8879 Annex K aka the "WebSGML adaptions".
DocBook is originally an SGML DocType and most of the DocBook formatters are written in DSSSL. Large amounts of documentation for open source software (and large amounts of O’Reilly books) is still SGML DocBook.
[1] https://en.wikipedia.org/wiki/DocBook#Sample_document