fix sql query issue