Studies might be renamed, but their UUIDs should be stable.
Look up the UUIDs of active studies in the events wh and compare them
(with a conversion) to mlwh study UUIDs.
Some other tweaks to make the query faster:
use UUID_TO_BIN instead of UNHEX(REPLACE...)
group by int primary key (fast) instead of a long string (slow)
Studies might be renamed, but their UUIDs should be stable. Look up the UUIDs of active studies in the events wh and compare them (with a conversion) to mlwh study UUIDs.
Some other tweaks to make the query faster: