1

I have the following query:

$this->db
     ->select('SQL_CALC_FOUND_ROWS null as rows
        ,table1.*
        ,table2.*
        ,table3.*', FALSE)
     ->from('table1')
     ->where('table1.column1', $user_id)
     ->join('table2', 'table2.column2 = table1.column2')
     ->join('table3', 'table3.column2 = table1.column2')
     ->group_by('table1.column2')
     ->order_by('table1.column2', 'DESC');

 $query = $this->db->get();

The problem is, there may not be a row in table 3 and if there is not, I would still like to return a result with the remainder of the query data. Please could someone advise how to achieve this?

2 Answers 2

1

you should do a left join on table3

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I had tried that and hadn't found it successful. 'Table 2' returns more than one row, so the query then doesn't then return all the rows of table 2
0

Use left join and also use group_by to get exact records:

$this->db->join('login_ranknames AS t4', 't4.id = t1.rank', 'left');
$this->db->group_by('t4.id');

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.