title: Mysql query two tables & get data in date wise or user wise
body: <p>I have two tables. The first one holds information about Hours:<br /></p>
  
  <pre><code>ID   |  activitydate   |  userid  |  phaseid  |  activityid  |  time  |
   3   |  2011-04-11     |    1     |     1     |      1       |  120   |
   4   |  2011-04-12     |    1     |     1     |      1       |  180   |
   5   |  2011-04-12     |    3     |     1     |      1       |  360   |
   6   |  2011-04-22     |    2     |     2     |      3       |  300   |
  </code></pre>
  
  <p>The 2nd table holding the data of Users:</p>
  
  <pre><code>  ID   |    userid       |  lastname |
     1   |      abc        |   ABC     |
     2   |      xyz        |   XYZ     |
     3   |      asd        |   ASD     |
     4   |      qwe        |   QWE     |
  </code></pre>
  
  <p>I need a query which generate below given format:</p>
  
  <pre><code>  Date     | ABC | XYZ | ASD | QWE |
  2011-04-11 | 120 |  0  |  0  |  0  |
  2011-04-12 | 180 |  0  | 360 |  0  |
  2011-04-22 |  0  | 300 |  0  |  0  |
  </code></pre>
  
  <p>This can be as below format:</p>
  
  <pre><code>  User  | 2011-04-11 | 2011-04-12 | 2011-04-13| .... | 2011-04-22 |...
    ABC   |    120     |    180     |     0     | .....|     0      |...
    XYZ   |     0      |     0      |     0     | .....|    300     |...
    ASD   |     0      |    360     |     0     | .....|     0      |...
    QWE   |     0      |     0      |     0     | .....|     0      |...
  </code></pre>
  
  <p>Any help is really appreciated!</p>