title: Subquery in Select Statement in Laravel 5.2
body: <p>I want to use this subquery in select statement</p>
  
  <pre><code>select category from `categories` WHERE id = `products`.`category_id`
  </code></pre>
  
  <p>Here is select statement part of my method</p>
  
  <pre><code>$query = $this-&gt;select(
     DB::raw('COUNT(DISTINCT(`order_details`.`product_id`)) as productCount'), 'products.category_id',
     DB::raw('('.DB::select('select category from `categories` WHERE id = `products`.`category_id` ').') AS category ')
  );
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'products.category_id' in 'where clause' (SQL: select category from `categories` WHERE id = `products`.`category_id` )
  </code></pre>
  
  <p>I hate using direct select statement. Because it is not good if i will change database.</p>
  
  <p>Despite of using direct select statement it is not working. How can i do that ?</p>