2

我正在尝试这个

$this->db->join('tableTwo as b','','CROSS');
$result = $this->db->get('tableOne as a')->result(); 

一些解决方案?

4

4 回答 4

4

codeigniter中cross join的解决方案:

$this->db->join('tableTwo as b','true');
$result = $this->db->get('tableOne as a')->result(); 
于 2013-03-21T17:59:25.083 回答
1

你应该这样使用它:

$this->db->join('tableTwo as b','true');
$result = $this->db->get('tableOne as a')->result(); 
于 2013-03-27T19:22:35.463 回答
1

在 codeigniter 3 中,您可以通过

$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

或通过将一个表传入 from 和另一个传入 get 方法

$result = $this->db->from('tableOne as a')
get('tableTwo as b')->result(); 
于 2018-09-11T17:47:41.617 回答
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
于 2021-01-18T18:24:38.923 回答