SELECT * FROM product_details WHERE (product_id =‘141’ or product_id =‘1980’) and date(date_time)>=‘2018-01-01’ group by product_id having count(*)>=2
I want to pick only those records having both product_id = 141 and product_id = 1980 so if product_id 141 is coming 10 times but there is no 1980 it should not be picked.
Sometimes it is simper to expand a Query and to spot why it is not working:
SELECT
*
FROM
product_details
WHERE
(
product_id = '141'
OR
product_id ='1980'
)
AND
date(date_time) >= '2018-01-01'
GROUP BY
product_id
HAVING
count(*) >= 2
Have you tried gradually building the query in PhpMyAdmin?
I would try omitting the AND, GROUP BY and HAVING clauses, notice the results then add the clauses one by one.