NXP-12558: fix query with join and subquery