私は3つのテーブルを持っていますが、3番目のテーブルのwhereステートメントを使用しても3番目のテーブルにはありません。私は左の結合を使用していますが、最初と2番目のテーブルから行を返します。上記のデータから今CI MySQLクエリ結合テーブルとwhere文がすべての行を返さない
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->( 'c.trans_location'、 '1')ここで)何があるとして、結果はアカウント4を返さないではないだろうtable_2とtable_3のacc_PID = '4'のデータですが、テーブル2とテーブル3にアカウント4のデータがなくても$ this-> db-> where( 'c .trans_location '、' 1 ')、結果はアカウント4も表示されますが、where join文を使用すると、左結合を使用してもテーブル1から行が返されません。
ありがとうございます。
where節の代わりにjoinで条件を追加してみます。 –
これはあなたを助けるかもしれないhttp://stackoverflow.com/questions/15992236/codeigniter-join-with-multiple-conditions –
@AmiteshKumar愚かな私!ありがとうございました。私は答えとして受け入れることができるように、あなたの答えを書いてください。 – Charas