title: How to use left join like right join in Doctrine
body: <p>So I've been racking my brain for a while now. In Doctrine there is no concept of right join. I know that you can use a left join like a right join but I can't figure it out for my example which is why I'm here.</p>
  
  <p>My example:
  I have an entity in Doctrine which has a one-to-one relationship with itself called "parent".
  I am trying to get all entities and their children(if they exist) with no duplicates. </p>
  
  <p>With a right join this is simple because I can say: </p>
  
  <pre><code>    SELECT parent.*, child.*
      FROM table child
      RIGHT JOIN table parent ON parent.id = child.parent_id
      WHERE parent.parent_id is null;
  </code></pre>
  
  <p>But using a left join I am returned results that I can not figure out what the where clause should be to filter them out.</p>
  
  <p>So my question is "Does doctrine have a way of doing right join" or "How can I use the left join operation like a right join"?</p>
  
  <p>---EDIT---</p>
  
  <p>You guys are correct in what you are saying about changing the ordering of tables I select from but I am using Doctrine so the relationship does child->parent. Here is my doctrine query:</p>
  
  <p>My Entity:</p>
  
  <pre><code>/**
   * @Entity
   * @Table(name="entity")
   */
  class Entity
  {
  ...
  /**
   * @OneToOne(
   *     targetEntity="Entity",
   *     fetch="EAGER"
   * )
   * @JoinColumn(name="parent_id", referencedColumnName="id")
   */
  private $parent;
  ...
  }
  </code></pre>
  
  <p>My doctrine select statement:</p>
  
  <pre><code>$em-&gt;createQueryBuilder()
  -&gt;select(array('child', 'parent'))
  -&gt;from('Entity', 'child')
  -&gt;leftjoin('child.parent', 'parent')
  -&gt;orderBy('parent.id','asc')
  -&gt;getQuery()
  -&gt;execute();
  </code></pre>
  
  <p>I am not sure how and IF I can switch the ordering of tables. I also tried creating another relationship from entity to itself (like the way I did parent) but called it child. But when I updated the db with the new schema doctrine threw errors.</p>
  
  <p>Any ideas? And Thanks for the quick responses!</p>
  
  <p>---EDIT 2---</p>
  
  <p>Left join sql and results:</p>
  
  <pre><code>SELECT child.id, child.changed_timestamp, child.parent_entity_id, parent.id,
    parent.changed_timestamp, parent.parent_entity_id 
  FROM content child 
  LEFT JOIN content parent ON child.parent_entity_id = parent.id   
  ORDER BY parent.id ASC
  
  child_id    child_timestamp parent_entity_id    parent_id   parent_timestamp    parent_entity_id
  1           8/16/12 20:29   NULL                NULL        NULL                NULL
  7           9/20/12 16:07   NULL                NULL        NULL                NULL
  8           8/17/12 16:08   NULL                NULL        NULL                NULL
  9           8/17/12 20:44   NULL                NULL        NULL                NULL
  10          8/17/12 21:03   NULL                NULL        NULL                NULL
  11          8/17/12 21:17   NULL                NULL        NULL                NULL
  194         9/19/12 9:58    NULL                NULL        NULL                NULL
  195         9/20/12 10:38   NULL                NULL        NULL                NULL
  196         9/19/12 11:58   NULL                NULL        NULL                NULL
  197         NULL            196                 196         9/19/12 11:58       NULL
  200         9/20/12 16:02   1                   1           8/16/12 20:29       NULL
  202         9/20/12 16:35   NULL                NULL        NULL                NULL
  204         9/21/12 8:41    NULL                NULL        NULL                NULL
  206         NULL            204                 204         9/21/12 8:41        NULL
  </code></pre>
  
  <p>Right join results:</p>
  
  <pre><code>SELECT child.id, child.changed_timestamp, child.parent_entity_id, parent.id, 
   parent.changed_timestamp, parent.parent_entity_id 
  FROM content child 
  RIGHT JOIN content parent ON child.parent_entity_id = parent.id   
  WHERE parent.parent_entity_id is null
  ORDER BY parent.id ASC
  
  child_id    child_timestamp parent_entity_id    parent_id   parent_timestamp    parent_entity_id
  200         9/20/12 16:02   1                   1           8/16/12 20:29       NULL
  NULL        NULL            NULL                7           9/20/12 16:07       NULL
  NULL        NULL            NULL                8           8/17/12 16:08       NULL
  NULL        NULL            NULL                9           8/17/12 20:44       NULL
  NULL        NULL            NULL                10          8/17/12 21:03       NULL
  NULL        NULL            NULL                11          8/17/12 21:17       NULL
  NULL        NULL            NULL                194         9/19/12 9:58        NULL
  NULL        NULL            NULL                195         9/20/12 10:38       NULL
  197         NULL            196                 196         9/19/12 11:58       NULL
  NULL        NULL            NULL                202         9/20/12 16:35       NULL
  206         NULL            204                 204         9/21/12 8:41        NULL
  </code></pre>
  
  <p>I want to achieve the results with the right join sql. Unique parent entities with their associated children(if they exists) but I need to achieve it using doctrine. Thanks again!</p>