Handling of 'GROUP BY' and selected columns

1. Ensure correct queries if the rest_of_query contains a 'GROUP BY'.
2. Create a correct subquery if there's only one id column.
Partially fixes #437