• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LEFT JOIN to a subquery using CI

#1
Hi all,

I'm trying to do a left join to a sub-query. When I code a simple LEFT JOIN like...


Code:
         //LEFT JOIN mytable ON mytable.myfield=maintable.myfield

        $this->db->join('mytable','mytable.myfield=maintable.myfield','left');

... everything works fine.

I need to do the following (equivalent SQL)...


Code:
LEFT JOIN(select * from othertable where othertable.id = 100) AS oth ON othertable.id=maintable.id


Codeigniter seems to do two things. It strips out the brackets around the subquery, and also produces SQL syntax as follows...


Code:
JOIN AS oth ON othertable.id=maintable.id USING (left)


This is run on a Mysql database and it fails for 'You have an error in your SQL syntax'

I've tried various permutations of this but the result is the same. My sub-query will always be the same so I can use a string for it. Is there a way that I can inject the sub query string into the middle of the query to achieve a LEFT JOIN on a sub query?

Peter
Reply


Messages In This Thread
LEFT JOIN to a subquery using CI - by peterlavin - 11-18-2015, 04:49 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.