Hi!
Subselects don't work in MySQL, it's strictly Access/Oracle/Ms SQL Server feature.
You have to do the select separately, put id values into array using PHP, join this array using implode(",", $array) and feed the resulting string to:
delete from tablename where id not in($string)
Hope it helps,
Stas