Fixed invalid sql query