SQL -
SELECT * FROM
(
(
SELECT pi.instid as instid, pi.iid as iid, 'itemcontent' as typ, ic.ic_name as name, ic.ic_value as value, pi.pi_left, pi.pi_right
FROM itemcontent ic, pageitem pi
WHERE pi.pid ='2246'
AND pi.iid = ic.iid
)UNION(
SELECT pi.instid as instid, pi.iid as iid, 'itemvalue' as typ, iv.iv_name as name, iv.iv_value as value, pi.pi_left, pi.pi_right
FROM itemvalue iv, pageitem pi
WHERE pi.pid ='2246'
AND pi.iid = iv.iid
)UNION(
SELECT pi.instid as instid, pi.iid as iid, 'instcontent' as typ, inc.instc_name as name, inc.instc_value as value, pi.pi_left, pi.pi_right
FROM instcontent inc, pageitem pi
WHERE pi.pid ='2246'
AND pi.instid = inc.instid
)UNION(
SELECT pi.instid as instid, pi.iid as iid, 'instvalue' as typ, inv.instv_name as name, inv.instv_value as value, pi.pi_left, pi.pi_right
FROM instvalue inv, pageitem pi
WHERE pi.pid ='2246'
AND pi.instid = inv.instid
)
) as t
ORDER BY instid, pi_left