update tActHd set bActHdUserRead=0 where 
liActHdActId in (
select
	TA.iActId
from tAct TA
where TA.liActKindId=1
and not TA.iActId in 
(
	--From/To je stejne jako e-mail zadatele z tPerson
	select
	TA.iActId
	from tAct TA
	inner join tHdTicket THD on TA.liActHdTicketId=THD.iHdTicketId
	inner join tPerson TP on TP.iPersonId=THD.liHdTicketUserPersonId
	where 
		TA.liActKindId=1 
		and not TP.sPersonEmail is null
		and
		(
			(lower(TA.sActFromEmail)=lower(TP.sPersonEmail))
			or (lower(TA.sActToEmail)=lower(TP.sPersonEmail))
		)
union
	--From/To je stejne e-mail zadatele z pozadavku
	select
		TA.iActId
	from tAct TA
	inner join tHdTicket THD on TA.liActHdTicketId=THD.iHdTicketId
	inner join tPerson TP on TP.iPersonId=THD.liHdTicketUserPersonId
	where 
		TA.liActKindId=1 
		and not THD.sHdTicketUserEmail is null
		and (TP.sPersonEmail is null or not THD.sHdTicketUserEmail = TP.sPersonEmail)
		and
		(
			(lower(TA.sActFromEmail)=lower(THD.sHdTicketUserEmail))
			or (lower(TA.sActToEmail)=lower(THD.sHdTicketUserEmail))
		)
)

)