mysql查询语句不返回_PHP-CI MySQL查询联接表,并且where语句不返回所...

我有3个表要联接,但是当我在第三个表上使用where语句,而第三个表没有它时,即使我使用的是left,它也不会返回第一和第二个表中的行加入.

Table 1

+---------+--------------+----------+

| acc_PID | acc_name | acc_type |

+---------+--------------+----------+

| 1 | Account 1 | 1 |

| 2 | Account 2 | 1 |

| 3 | Account 3 | 2 |

| 4 | Account 4 | 1 |

+---------+--------------+----------+

Table 2

+-------------+-----------------+-----------+

| journal_PID | journal_account | trans_PID |

+-------------+-----------------+-----------+

| 1 | 1 | 1 |

| 2 | 2 | 2 |

| 3 | 1 | 3 |

+-------------+-----------------+-----------+

Table 3

+-----------+----------------+

| trans_PID | trans_location |

+-----------+----------------+

| 1 | 1 |

| 2 | 1 |

| 3 | 2 |

+-----------+----------------+

// CI query

$this->db->join('table_2 b', 'a.acc_PID = b.journal_account', 'LEFT');

$this->db->join('table_3 c', 'b.trans_PID = c.trans_PID', 'LEFT');

$this->db->where('a.acc_type', '1');

$this->db->where('c.trans_location', '1');

$this->db->group_by('a.acc_PID');

$query = $this->db->get('table_1 a');

$result = $query->result();

现在根据上面的数据,如果我使用($this-> db-> where(‘c.trans_location’,’1′)),结果将不会返回帐户4,因为没有acc_PID =’的数据table_2和table_3中的4′,但是即使表2和表3中没有帐户4的数据,我也希望结果也返回帐户4,而没有$this-> db-> where(‘c.trans_location’ ,’1′),结果也显示帐户4,但是使用where location语句,即使我使用了左连接,它也不会返回表1的行,也不应该从表1返回结果吗?

先感谢您.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值