Manoj Borah
Manoj Borah

Reputation: 21

How to use LEFT JOIN in DOCTRINE

I have used following code for simple join in Doctriner in Codeigniter:

$query = $this->em->createQuery('SELECT u.name,u.subject,pds.subject_name FROM PdContact u,PdSubject pds WHERE pds.id=u.sub_id');

But how to do left join? When I tried to to left join it shows error.

Please suggest solution.

Upvotes: 1

Views: 54

Answers (1)

Nawfal Serrar
Nawfal Serrar

Reputation: 2263

You can use this :

    $sql = "SELECT u.name,u.subject,pds.subject_name FROM PdContact u LEFT JOIN PdSubject pds  ON pds.id=u.sub_id;";
    $connection = $this->em->getConnection();
    $cleanreq = $connection->prepare($sql);
    $cleanreq->execute();
    $result = $cleanreq->fetchAll();
    return $result;

For more infos on Joining you can check this doc : http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html

Upvotes: 1

Related Questions