Given I have a query like:
SELECT count(mm.id) AS c
FROM merchant_mobile mm
INNER JOIN mobile m ON mm.mobile_id = m.id
LEFT JOIN merchant_mobile_customer mmc ON (mm.id = mmc.merchant_mobile_id)
INNER JOIN merchant_mobile_tag mmt ON mm.id = mmt.merchantmobile_id
INNER JOIN tag t ON t.id = mmt.tag_id
WHERE mm.merchant_id = ?
AND mm.status LIKE ?
AND (mm.last_promo_sms_date <= ?
OR mm.last_promo_sms_date IS NULL)
AND t.name = ?
AND t.name = ?
ORDER BY mm.last_promo_sms_date ASC
I need to perform queries to select:
- Matches for exact tag combination: eg: pretty AND blonde
- Matches for any combination, but at least one of them: pretty OR blonde
Is it possible to make with just one query?
Do I need a subquery?
Is my schema ok?
Best Answer
This is how I solved it:
For exact combination
For at least one