I have two tables: users
and userlogs
table1
----------
id | name
----------
1 | A
2 | B
3 | C
4 | D
table2
----------
user_id | date
----------
1 | 2015-12-17
2 | 2015-12-18
3 | 2015-12-19
4 | 2015-12-20
If I do LEFT JOIN with selected date, it only gives data that exist in table 2.
SELECT r.user_id, count(r.user_id) as count
FROM table1 a LEFT OUTER JOIN table2 r ON ( r.user_id = a.id )
WHERE r.created_at BETWEEN '2015-12-17' AND '2015-12-19'
GROUP BY a.id
I get the following
Result
----------
user_id | count
----------
1 | 1
2 | 1
3 | 1
I need something like the following:
Result
----------
user_id | count
----------
1 | 1
2 | 1
3 | 1
4 | 0
I have tried many different ways, but was unsuccessful.