More SQL thinning work