Codeigniter中如何在没有条件的情况下选择联接多个表?
问题描述:
我想在codeigniter中使用join选择多个表,但是我不想在下面的代码中添加任何条件
I want to select multiple table using join in codeigniter but I don't want to make any conditional as below code
public function get_invoice(){
$this->db->select('isp.*,dp.*,ip.*');
$this->db->from('isp');
$this->db->join('dp','dp.status = isp.status');
$this->db->join('isp','isp.status = ip.status');
$this->db->limit(5000);
$this->query = $this->db->get();
if($this->query->num_rows()>0){
return $this->query->result();
}
}
但是我想获取所有数据
那我该如何在无条件的情况下从多个表中选择数据?
感谢帮助
答
是的,您可以无条件加入查询。内左右联接需要条件。因此,您可以执行交叉联接。就像这样
Yes you can join query without condition. INNER LEFT RIGHT JOINS need condition.So you can do Cross JOIN.LIKE this
public function get_invoice(){
$this->db->select('isp.*,dp.*,ip.*');
$this->db->from('isp,dp,ip');
$this->db->limit(5000);
$this->query = $this->db->get();
if($this->query->num_rows()>0)
{
return $this->query->result();
}
}
但是如果您的isp在Cross JOIN有100条记录,dp有20条记录,ip有50条记录它将产生(100 * 20 * 50)条记录。希望您知道CROSS,LEFT,INNER,RIGHT JOIN的作用。
But at Cross JOIN if your isp has 100,dp has 20, and ip has 50 record It will produce (100*20*50) record.I hope you know what CROSS,LEFT,INNER,RIGHT JOIN do.