Incorporating a dissolve in a query

I am trying to extract maps for the mainland of countries. I don’t want any outlying islands or overseas possessions - I just want the mainland. There are about 50 I’m after but a good example is Spain. Using the query below I can extract mainland Spain by listing all the internal administrative areas.

[out:json];
rel["ISO3166-2"~"^(ES-AN|ES-AR|ES-AS|ES-CB|ES-CL|ES-CM|ES-CT|ES-EX|ES-GA|ES-RI|ES-MD|ES-MC|ES-NC|ES-PV|ES-VC)$"];
out geom;

This returns just the mainland. Problem is, the data returned contains all the internal boundaries. These boundaries are ~50% of the data returned, and I also have a bit of a job processing the data to remove the internal boundaries. What I’m really after is for OSM to do a dissolve on the data before returning it to me. This will reduce the data I need to download, and relieve me of the need to post process the data.

Any trick I can use to dissolve the internal boundaries of the returned map?

If you have a minute, or two:

[out:json];
rel["ISO3166-2"~"^(ES-AN|ES-AR|ES-AS|ES-CB|ES-CL|ES-CM|ES-CT|ES-EX|ES-GA|ES-RI|ES-MD|ES-MC|ES-NC|ES-PV|ES-VC)$"]->.r;
foreach .r->.rone
{
  (.r; - .rone;)->.rwithout;
  (way(r.rone); - way(r.rwithout););
  out geom;
};

We ask for the ways that are part of one of the relations but not of any other of them, iterating over all relations.