Fixes to SQL queries.

Fixes to SQL queries.