Improved database query for profilunit export