title: Drupal - Query to count all nodes of content_type "A" in which field_b is "X"
body: <p>I need to make a query for a drupal site. Initially I just needed to COUNT the number of nodes for a content type:</p>
  
  <pre><code>$query = "SELECT COUNT(*) amount FROM {node} n WHERE n.type ='A'";
  $result = db_query($query)-&gt;fetch();
  return $result-&gt;amount;
  </code></pre>
  
  <p>Now I need that but only for nodes that have the field_b equal to 'X'. How can I do this?</p>
  
  <pre><code>I tried EntityFieldQuery without sucess:
  
  $query = new EntityFieldQuery;
  $query-&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', 'A')
    -&gt;fieldCondition('field_b', 'value', 'X');
  
  $results = $query-&gt;execute();
  return $results-&gt;amount;
  </code></pre>
  
  <p>Any help?</p>