fix sql statement for performance