【MySQL】mysql-left join陷阱

.where和and的差异

SELECT
    ota_distributor_product_relation.ota_id,
    ota_distributor_product_relation.ota_name,
    ota_distributor_product_relation.sale_status,
    ota_distributor_product_relation.id,
    ota_stock_price.guide_price,
    ota_stock_price.purchase_price,
    ota_stock_price.scenic_price,
  ota_stock_price.stock
FROM
    ota_distributor_product_relation
LEFT JOIN ota_stock_price ON ota_distributor_product_relation.id = ota_stock_price.relation_id
AND ota_distributor_product_relation.ticket_id='06d02f2d583746f2ad7ac4a0407f3499' AND ota_stock_price.sp_date='2017-06-29'

 

SELECT
    ota_distributor_product_relation.ota_id,
    ota_distributor_product_relation.ota_name,
    ota_distributor_product_relation.sale_status,
    ota_distributor_product_relation.id,
    ota_stock_price.guide_price,
    ota_stock_price.purchase_price,
    ota_stock_price.scenic_price,
  ota_stock_price.stock
FROM
    ota_distributor_product_relation
LEFT JOIN ota_stock_price ON ota_distributor_product_relation.id = ota_stock_price.relation_id
where ota_distributor_product_relation.ticket_id='06d02f2d583746f2ad7ac4a0407f3499' AND ota_stock_price.sp_date='2017-06-29'

 

可以看到两种查询得到的结果不一样,具体原因可以查看这篇博文:

http://www.oschina.net/question/89964_65912

以前没注意,不知道是不是写了很多bug = =。

 

转载于:https://www.cnblogs.com/flydkPocketMagic/p/MySQL.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值