select a.[TicketOrderID],a.[Takedate],c.ticketorderid
from ticketorder a
left join [order] b
on a.ticketorderid=b.orderid
left join [ticketOrder] c
on a.ticketOrderid=c.ticketorderid and c.ticketorderid=0
from ticketorder a
left join [order] b
on a.ticketorderid=b.orderid
left join [ticketOrder] c
on a.ticketOrderid=c.ticketorderid and c.ticketorderid=0