You seem to want to delete from media
where the corresponding record doesn't exist in movie
. You can do this as a single query.
delete from media
where not exists (select 1 from movie m where m.id = media.media_id);
It does seem strange to me that the field movie.id
would correspond to media.media_id
, but that is how your original query is written.
EDIT:
As for your question, you can write the delete
as:
delete from media
where find_in_set(media_id, @list_id_remove) > 0;