在这种情况下,您需要左连接。
SELECT
tb1.booking_ref, tb1.investor, tb2.cost
FROM
tb1
left join tb2
on tb1.booking_ref = tb2.booking_ref
and tb1.investor = tb2.investor
WHERE tb1.investor = ''12345''
SQL选择匹配记录存在且没有匹配记录的位置
在这种情况下,您需要左连接。
SELECT
tb1.booking_ref, tb1.investor, tb2.cost
FROM
tb1
left join tb2
on tb1.booking_ref = tb2.booking_ref
and tb1.investor = tb2.investor
WHERE tb1.investor = ''12345''