title: Symfony Doctrine - If else in query builder
body: <p>I want to choose the joined table by the result of one field from other.</p>
  
  <p>In detail there is a field catId. This is the id of the category with a letter s or c in front. And if there is a c like c6 i must join the category table and look there for the id. If s, i have to join the subcategory table and look for the id. So i also have to cut the letter in front of the result.</p>
  
  <p>How can i do this in query builder directly in the code?
  I hope this explains it:</p>
  
  <pre><code>public function contentByNId($NId)
  {
      return $this-&gt;createQueryBuilder('c')
          -&gt;where('c.news = :news')
          -&gt;setParameter('news', $NId)
  
          // the result from c.catId as a number with s for subcategory or c for category in front. like s21 or c6
  
          // if in c.catID is an s than
          // cut the letter (s or c) from c.catId for the leftJoin to  replacedCatID
          -&gt;leftJoin('AppBundle:subcategories', 's', 'WITH', 'c.replacedCatID = s.id')
          //
          //
          //  else
          //
          //
          -&gt;leftJoin('AppBundle:categories', 's', 'WITH', 'c.replacedCatID = s.id')
          //
          //
  
          -&gt;addSelect(
              'c',
              's.headline'
          )
          -&gt;getQuery()
          -&gt;getArrayResult();
  }
  </code></pre>