我正在尝试这个
$this->db->join('tableTwo as b','','CROSS');
$result = $this->db->get('tableOne as a')->result();
一些解决方案?
答案 0 :(得分:3)
codeigniter中的交叉连接解决方案:
$this->db->join('tableTwo as b','true');
$result = $this->db->get('tableOne as a')->result();
答案 1 :(得分:0)
你应该这样使用它:
$this->db->join('tableTwo as b','true');
$result = $this->db->get('tableOne as a')->result();
答案 2 :(得分:0)
$this->db->join('tableTwo as b','1=1'); //true relation
$result = $this->db->get('tableOne as a')->result();
$result = $this->db->get(['tableOne as a','tableTwo as b'])->result();
$result = $this->db->from(['tableOne as a','tableTwo as b'])
get()->result(); //by this method you can add as many table you want to join
或通过在get方法中将一个表从另一个表中传入
$result = $this->db->from('tableOne as a')
get('tableTwo as b')->result();
答案 3 :(得分:0)
对于那些来看 Codeigniter 4 答案的人:
// tableOne is defined in the model
$this->model->join('tableTwo', 'column_x= column_y', 'cross');
第一个参数是表名,下一个参数是连接条件,第三个参数是连接类型。
所以如果你有一个这样的 SQL 语句:
cross join producto_resumen_color on prre_id = prco_prre_id
你会这样做:
->join('producto_resumen_color','prre_id = prco_prre_id', 'cross')
您可以在 CI 的用户指南中找到更多信息。
https://codeigniter.com/user_guide/database/query_builder.html?highlight=join#join
join($table, $cond[, $type = ''[, $escape = NULL]])
Parameters:
$table (string) – Table name to join
$cond (string) – The JOIN ON condition
$type (string) – The JOIN type
$escape (bool) – Whether to escape values and identifiers