Added support for building SQLs with sub-queries