Sub-query support in from() and join()

Usage: $query->from(['foo' => $subquery])->join(['bar' => $subquery2], 'foo.id', '=', 'bar.id');

Taken from @jarredholman's work: 3ec55a146b4ec284e40e503088b15b47fff816a4

A previous PR was created (#4238) but was closed due to implementation. The implementation in this PR is more correct.
Braces for control statements should be on a new line please.