I look around here and couldn't find answer and I can't seem to figure this out. What I'm look for is this:
I have two tables: Table 1:
+---------+---------------------+
| user_id | created_date |
+---------+---------------------+
| 1 | 2013-05-17 11:59:59 |
| 1 | 2012-05-19 12:00:00 |
| 1 | 2014-06-11 12:00:02 |
| 1 | 2013-05-17 12:00:03 |
| 3 | 2014-01-12 14:05:00 |
| 3 | 2012-05-17 14:05:01 |
| 3 | 2013-05-17 15:30:00 |
+---------+---------------------+
Table 2:
+---------+---------------------+
| post_id | created_date |
+---------+---------------------+
| 1 | 2013-05-17 11:59:59 |
| 1 | 2012-05-19 12:00:00 |
| 1 | 2014-06-11 12:00:02 |
| 1 | 2013-05-17 12:00:03 |
| 3 | 2014-01-12 14:05:00 |
| 3 | 2012-05-17 14:05:01 |
| 3 | 2013-05-17 15:30:00 |
+---------+---------------------+
I'm looking to count both the number of users and the number posts I have in the database for each month. The result should look like
+----------------+-------------+-------------+
| date | users | posts |
+----------------+-------------+-------------+
| january 2013 | 27 | 10 |
| march 2013 | 108 | 101 |
| june 2013 | 270 | 100 |
| october 2013 | 2 | 1 |
+----------------+-------------+-------------+
I've started the mySQL query like this:
SELECT CONCAT_WS(' ', YEAR(u.date_created),MONTHNAME(u.date_created)) AS date,COUNT(*) AS users
FROM users AS u
UNION
SELECT CONCAT_WS(' ', YEAR(p.date_created),MONTHNAME(p.date_created)) AS date,COUNT(*) AS posts
FROM post AS p
GROUP BY YEAR(date_created),MONTHNAME(date_created)
But this only return two columns not three. Any help.
Thanks