Fix ticket linking sql.