SELECT
a.order_no AS order_no,
b.book_id AS book_id,
c.subs_package_id AS subs_package_id
from ((`test`.`orders_paid` `a` left join `test`.`orders_book` `b` on((`a`.`order_no` = `b`.`order_no`))) left join `test`.`orders_subscription` `c` on((`a`.`order_no` = `c`.`order_no`)))
select
p.order_no, tmp.book_id, tmp.subs_package_id from orders_paid p
left outer join
(
select order_no, book_id , null as subs_package_id from orders_book
union
select order_no, null as book_id, subs_package_id from orders_subscription
) as tmp
on p.order_no = tmp.order_no