SELECT
a.id
,b.order_id,b.attr
FROM
tourist_order a
LEFT JOIN order_attr b
ON a.id = b.order_id
AND b.attr=‘order_status‘
WHERE
b.order_id IS NULL
AND a.create_type!=19
AND a.added_time>=‘2014-01-01‘
AND a.sign_date=‘0000-00-00‘
AND a.back_time>NOW()
# AND a.id=3526098
目标是查询table表中没有attr等于"order_status"的订单号
将AND b.attr=‘order_status‘放在where前和where后是不一样的。
where后面的语句会过滤之前left join的结果