Optimized SQL queries