Welcome Guest, Not a member yet? Register   Sign In
my querybuilder is not working
#1

Hello,

I'm trying to convert this raw query to query builder :
 Raw query :

Code:
SELECT a.id as ID, a.name as NAME, b.name as DEPT
FROM designations AS a
LEFT JOIN departments AS b ON b.id = a.department_id;
Query Builder :

Code:
  $this->builder()
            ->select('a.id as id, a.name as name, b.name as dept_name')
            ->from('designations AS a')
            ->join('departments as b', 'b.id = a.department_id', 'left')
            ->get();




But query builder is not working as expected, I'm unable to echo the dept_name in the view, it returns null.
Reply
#2

Maybe
PHP Code:
$db->getLastQuery() 

helps you to find the error in the query.
Reply
#3

[quote pid="411987" dateline="1692695462"]
Try without the alias..

PHP Code:
$this->builder()
            ->select('designations.id as id, designations.name as name, departments.name as dept_name')
            ->from('designations')
            ->join('departments''departments.id = designations.department_id''left')
            ->get(); 

[/quote]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB