简体   繁体   English

在codeigniter中的join语句中应用条件

[英]Apply condition on join statement in codeigniter

I am facing a problem with my codeigniter mysql query. 我的codeigniter mysql查询遇到问题。 The problem is i want to introduce a if condition on join statement, If that join doesn't return data then join another table. 问题是我想在连接语句上引入if条件,如果该连接不返回数据,则连接另一个表。 for example : 例如 :

$this->db->select(*);
if(!$this->db->join(XYZ,XYZ.id=abc.id)){
   $this->db->join(PQR,PQR.id=abc.id)
}

I want something like this, Is there any way to apply this approach. 我想要这样的东西,有没有办法应用这种方法。 Thanks 谢谢

Take reference of my example,it may help you out 参考我的例子,它可能会帮助你

$this->db->select(*);
$this->db->set('tbl1.user_time_index', "CASE WHEN tbl1.status = 'OK' THEN tbl1.emp_time_index ELSE tbl2.user_time_index END", FALSE);
$this->db->where('tbl1.user_id', 100);

Here CASE statement is used which works as if{}else{} statement 这里使用的CASE语句就好像{} else {}语句一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM