Fixed sql query issue