I am trying to execute a query to get the between data values. 
I have seen some questions here but my query is more complicated.
this is the query:
SELECT calendar.datefield AS DATE, 
IFNULL( count( lead.insertDate ) , 0 ) AS task
FROM lead 
RIGHT JOIN calendar ON ( DATE( lead.insertDate ) = calendar.datefield ) 
AND lead.lpid =  '40' 
WHERE insertDate BETWEEN '2016-01-05' AND '2016-01-23'
GROUP BY DATE
I think that the problem is in the query syntax, the query works good until i add the where row.
 
     
    