mysql - select record which is not present in other table in codeigniter -


i have used following query select rows tables.

table 1:  id  description status add_date   topicid   1   xyz         0      22-3-13     5     2   pqr         0      21-3-13     5  3   abc         0      20-3-13     5  4   sdd         0      22-3-13     5   table2:  id     otherid     1       2   2       3 

this query gives me record table1 want select record not in table2.
table1 'id' not present in table2 'otherid'.
in case want select record table1 id 1 , 4.because not present in table2 'otherid'.

$topicid = 5;  $q =$this->db->select(array(             't1.id id',             't1.description',             't1.topicid',             't1.add_date'))             ->from('table1 t1')             ->where('t1.topicid',$topicid)             ->where('t1.status',0)             ->order_by('t1.add_date desc)->get(); 

try query work

$topicid = 5;  $q =$this->db->select(array(             't1.id id',             't1.description',             't1.topicid',             't1.add_date'))             ->from('table1 t1')             ->where('t1.topicid',$topicid)             ->where('t1.status',0)             ->where('t1.id not in (select otherid table2)',null,false)             ->order_by('t1.add_date desc)->get(); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -