Mysql 左连接未按预期工作

Mysql Left Join Not working As Expected

我正在尝试一个简单的左连接,但它给我带来了问题。我需要列出所有客户 (table a),无论他们是否在特定日期范围内有发票 (table b)。我的两次尝试都产生了唯一一个拥有该期间发票的客户:

select b.clientname,a.* from invdata a
   left join clidata b on a.clidataid=b.recordid
      where b.recstatus=1 and b.isactive=1
      and a.reccreate between '2015-04-01 00:00:00' and '2015-04-30 23:59:59';

select a.clientname,b.* from clidata a
   left join invdata b on a.recordid=b.clidataid
      where a.recstatus=1 and a.isactive=1
      and b.reccreate between '2015-04-01 00:00:00' and '2015-04-30 23:59:59';

请稍加帮助。谢谢!!

Left join with where条件为inner join,会根据where条件过滤数据,您可能需要将where条件移动到joining条件

  select b.clientname,a.* from invdata a
  left join clidata b on a.clidataid=b.recordid
  and b.recstatus=1 and b.isactive=1
  and a.reccreate between '2015-04-01 00:00:00' and '2015-04-30 23:59:59';