(SELECT me.id, me.bu_id, me.description, me.contact_name, me.contact_phone, me.contact_email, me.creation_ts, (SELECT COUNT( * ) FROM customer you INNER JOIN box boxes ON boxes.customer_id = you.id INNER JOIN device devices ON devices.box_id = boxes.id WHERE ( you.id = me.id )) FROM customer me)