select t1.*
from (select sys_erpupdatelogid,
             request,
             status,
             errmsg,
             erpbillno,
             type,
             response,
             createby,
             createdate
      from sys_erpupdatelog
      where siteid = $siteid$
        and ownertable = 'sa_order'
        and ownerid = $sa_orderid$
      union all
      select t1.sys_erpupdatelogid,
             t1.request,
             t1.status,
             t1.errmsg,
             t1.erpbillno,
             t1.type,
             t1.response,
             t1.createby,
             t1.createdate
      from sys_erpupdatelog t1
               inner join sa_orderitems_change t2
                          on t1.siteid = t2.siteid and t1.ownerid = t2.sa_orderitems_changeid and
                             t1.ownertable = 'sa_orderitems_change'
      where t1.siteid = $siteid$
        and t2.sa_orderid = $sa_orderid$) t1