2017-04-03 81 views
0

我试图执行查询,从表1中得到的数据和应用,其中上表2 这一条款是一个示例查询上的代码点火器获取两个表中的数据

SELECT * FROM table1,table2 WHERE `hide` = 0 AND `reject` = 0 AND `disable` = 0 AND `private` = 0 AND `table2`.`wepay_account_id` != '' ORDER BY `table1_id` DESC LIMIT 40 

此查询执行执行在数据库中,但在代码点火器不执行

我试图将此代码模型

$this->db->limit($limit, $start); 
     $this->db->where('hide', 0); 
     $this->db->where('reject', 0); 
     $this->db->where('disable', 0); 
     $this->db->where('private', 0); 
     $this->db->where('table2.wepay_account_id !=',""); 
     $this->db->from('table1','table2'); 
     $this->db->order_by('table1', 'DESC'); 
     $query = $this->db->get(); 
     $a=$this->db->last_query(); 
     print_r($a); 
     exit; 

但我面对这个错误

Error Number: 1054 

Unknown column 'table2.wepay_account_id' in 'where clause' 

SELECT * FROM (`table1`) WHERE `hide` = 0 AND `reject` = 0 AND `disable` = 0 AND `private` = 0 AND `table2`.`wepay_account_id` != '' ORDER BY `table1_id` DESC LIMIT 40 
+0

Plz,给我们两张表的模式。 – Sharif

+0

secema不是问题.... $ this-> db-> from('table1','table2');当查询执行table2不显示..看起来错误SELECT * FROM('table1').. table2丢失 –

+0

其中是select语句?我的意思是''$ this-> db-> select('table1.SOMETHING,table2.SOMETHING');'' – Sharif

回答

2

在此代码段中选择用于table1。没有table2

它不是posisble添加条件为table2wepay_account_id

使用此连接(),

$this->db->from('table1'); 
$this->db->join('table2', 'table1.id = table2.id') 
+0

我需要table2.wepay_account_id不为空.. –

+0

你必须使用table2作为主表或连接表,否则你不能像这样访问 – Kushan

+0

谢谢..你的建议解决了我的问题 –

0

$this->db->from('table1'); 
$this->db->join('table2','true'); 

这种替代

$this->db->from('table1','table2'); 

将equillent您简单的MySQL查询。

相关问题