0

Im having trouble converting this code to codeigniter. Please help

SELECT * FROM table1
LEFT JOIN table2 ON table2.number = table1.number
WHERE table2.number IS NULL
2
  • Have you looked here codeigniter.com/user_guide/database/… Commented Feb 2, 2016 at 3:17
  • yes, cant find instructions for IS NULL. Commented Feb 2, 2016 at 3:29

5 Answers 5

2

Use below code.

$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2 ', 'table2.number = table1.number','left');
$this->db->where('table2.number IS NULL'); 
$query = $this->db->get();
Sign up to request clarification or add additional context in comments.

Comments

1

try this

$this->db->query('YOUR QUERY HERE');

example:

 if($this->db->query('SELECT * FROM table1 LEFT JOIN table2 ON table2.number = table1.number WHERE table2.number IS NULL') )
  {  
     echo 'success';
  }
   else
       echo 'check your query';

Comments

0
$this->db->where('table2.number IS NOT NULL', null, false)

OR

$this->db->where(array('table2.number' IS NOT NULL));

Comments

0

You can do it like this.

$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2 ', 'table2 .user_id = table1.id','left');
$this->db->where('table1.users_id', $id); 
$query = $this->db->get();

Comments

0

use this:

$this->db->select('*')
         ->from('table1')
         ->join('table2 ', 'table2.number = table1.number','left')
         ->where('table2.users_id', NULL ); 
$query = $this->db->get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.