Optimized sql a bit