Fix missing select clause on some queries. Closes #1236. Closes #1223.