How to get rid of variations with unspecified attributes

I’ve managed to write an SQL query that would get all product variation IDs that do not have both size and color set up (not present in the wp_postmeta table). After that I just need to loop through these IDs and delete those variations using wp_delete_post. This is the query:

SELECT p.ID 
FROM wp_posts p 
LEFT JOIN wp_postmeta pm 
ON p.ID = pm.post_id 
WHERE p.post_type="product_variation" 
AND (pm.post_id NOT IN (SELECT post_id FROM wp_postmeta WHERE meta_key = 'attribute_pa_size' OR meta_key = 'attribute_pa_color')) 
GROUP BY ID 

Works well for my case. I was originaly asking about variations that has at least one attribute unspecified, but turned out that wouldn’t be the solution, I had to look for variations with boths attributes empty.