title: MySQL multiple results from one table in one statement
body: <p>I'm trying to use multiple select query in two tables:</p>
  
  <p>Table1 -> infoTab:</p>
  
  <pre><code>  theType   |          theTime    | theCount 
  ------------+---------------------+----------
   WithPinIt  | 2017-04-01 13:00:00 | 45
   WithPinIt  | 2017-04-01 13:00:00 | 100
   WithMinIt  | 2017-04-01 13:00:00 | 75
   WithQinIt  | 2017-05-01 13:00:00 | 45
   WithMinIt  | 2017-06-01 13:00:00 | 55
  </code></pre>
  
  <p>Table2 ->  defsTab:</p>
  
  <pre><code>   theId  |   theDefs   |   theType
  ----------+-------------+-------------
  1         |  defQs      |  WithQinIt 
  1         |  defOs      |  WithOinIt 
  1         |  defJs      |  WithJinIt 
  </code></pre>
  
  <p>What I'm trying to get is a result like this:</p>
  
  <pre><code>          theTime    |  P  |  M 
  ---------------------+-----+-----
  2017-04-01 13:00:00  | 145 | 
  2017-04-01 13:00:00  |     | 75 
  2017-06-01 13:00:00  |     | 55
  </code></pre>
  
  <p>So far I used this query:</p>
  
  <pre><code>SELECT   
      theTime,   
      (SELECT SUM(theCount) AS pSum FROM infoTab WHERE theType NOT IN (SELECT content FROM defsTab) AND theType LIKE '%P%' GROUP BY theTime) AS Ps,   
      (SELECT SUM(theCount) AS cSum FROM infoTab WHERE theType NOT IN (SELECT content FROM defsTab) AND theType LIKE '%C%' GROUP BY theTime) AS Cs   
  FROM infoTab 
  </code></pre>
  
  <p>But it does not work... any help?</p>