title: MySQL SELECT via xref table plus get count of another table's rows
body: <p>Sorry about the title. I'm not sure how to properly describe the problem.</p>
  
  <p>I have four tables, tables A, B, X and D. A and B have a many-to-many relationship so I'm using X as the link table. </p>
  
  <p>Here's the structure:</p>
  
  <p><img src="https://i.stack.imgur.com/d8YFR.png" alt="DB Structure"></p>
  
  <p>Assuming all I have is an ID corresponding to a row in table A, I want to select the rows in table B that match up with that ID plus a count of all rows in table D that have the same <code>b_id</code>. Eh, I suck at explaining in words.</p>
  
  <p>Here's what I would like (<strong>all I have to search with is an ID which corresponds to a row in table A</strong> -- let's just say I have an "A"):</p>
  
  <pre><code>-------------------------------------------------------------
  | b.id | (A COUNT of how many rows in D have a b_id = b.id) |
  -------------------------------------------------------------
  |  1   |                       20                           |
  -------------------------------------------------------------
  |  4   |                       12                           |
  -------------------------------------------------------------
  </code></pre>
  
  <p>So, according to the above results, this particular "A" has two "B"s. One of those "B"s has 20 "D"s and the other has 12 "D"s.</p>
  
  <p>How can I write a single query to give me the results I'm after (again, all I'm searching with is an ID in table A)?</p>