Add support for SELECT DISTINCT
Fix handling of subqueries within first part of SELECT