update ClassifyBasket set classifyBasketStatus=2
where exists (
select 1 from TousseItem ti
join ClassifiedItem ci on 
  (ci.toussedefinition_id=ti.tousseDefinitionId 
  or ci.tousseDefinitionID=ti.tousseDefinitionId) and ti.recyclingApplication_ID=ci.invoicePlanID
where ClassifyBasket.id=ci.classifybasket_id  
)
and not exists (
select 1 from TousseItem ti
join ClassifiedItem ci on 
(ci.toussedefinition_id=ti.tousseDefinitionId 
or ci.tousseDefinitionID=ti.tousseDefinitionId)
and ti.recyclingApplication_ID=ci.invoicePlanID
where ClassifyBasket.id=ci.classifybasket_id 
and (ti.isTerminated is null or ti.isTerminated=0)
) and (classifyBasketStatus is null or classifyBasketStatus=0);