标签:
即:on后面的条件筛选参与连接的记录,主表中的记录会全部出现结果集中,而只有符合on条件的从表记录才会出现在结果集中。
SELECT A.ORDER_ID, B.TRANS_TYPE FROM GW_GATEWAY_ORDER A LEFT JOIN SYS_MCHT_SETTLE_DETAIL B ON A.ORDER_ID = B.ORDER_ID WHERE A.ORDER_ID >= 20101209150044021 AND A.ORDER_ID <= 20101210150048099;
结果:
ORDER_ID * TRANS_TYPE
20101209150044021 1
20101209150044021 2
20101210141359000 1
20101210144447001
SELECT A.ORDER_ID, B.TRANS_TYPE FROM GW_GATEWAY_ORDER A LEFT JOIN SYS_MCHT_SETTLE_DETAIL B ON A.ORDER_ID = B.ORDER_ID AND B.trans_type = 1 WHERE A.ORDER_ID >= 20101209150044021 AND A.ORDER_ID <= 20101210150048099;
结果:
ORDER_ID * TRANS_TYPE
20101209150044021 1
20101210141359000 1
20101210144447001
SELECT A.ORDER_ID, B.TRANS_TYPE FROM GW_GATEWAY_ORDER A LEFT JOIN SYS_MCHT_SETTLE_DETAIL B ON A.ORDER_ID = B.ORDER_ID WHERE A.ORDER_ID >= 20101209150044021 AND A.ORDER_ID <= 20101210150048099 AND B.trans_type = 1;
结果:
ORDER_ID * TRANS_TYPE
20101209150044021 1
20101210141359000 1
inner join、left join、right join等的区别
标签:
原文地址:http://www.cnblogs.com/qhorse/p/4702487.html