Here i want to get result only if both the numbers are present for both type
. For example in this number 888
is present only for super
type and 000
is present only for type box
. I don't want to list only the number that is present for only one type
. Want to get the numbers if it is present for both the type
. Here is my code please have a look
$query=$this->db->query("
SELECT T.number
, W.number
, max(T.MOST_FREQUENT) max_val
, W.MOST_FREQUENT
, W.product_id
from
( SELECT product_id
,date_status
,number
, bill_details.id as b_id
, SUM(quantity ) AS MOST_FREQUENT
FROM bill_details
WHERE date_status = 1
AND product_id IN(8,7)
GROUP
BY product_id,number
HAVING SUM(quantity) >= $d_limit_3
ORDER
BY SUM(quantity) DESC
LIMIT 500
) T
JOIN
( SELECT product_id
,date_status
,number
, bill_details.id as b_id
, SUM(quantity) AS MOST_FREQUENT
FROM bill_details
WHERE date_status = 1
AND product_id IN(8,7)
GROUP
BY product_id
, number
HAVING SUM(quantity) >= $d_limit_3
ORDER
BY SUM(quantity) DESC
LIMIT 500
) W
ON T.number = W.number
group
by T.number
, W.MOST_FREQUENT
, W.product_id
, W.number
ORDER
BY concat(lpad(max(T.MOST_FREQUENT), 100, '0'), T.number) DESC
, T.number
, W.MOST_FREQUENT
, W.product_id
");
return $query->result();