I’m having some trouble with an If statement in mysql – I’m pretty new to this.
SELECT c.* FROM cca_coupons c
JOIN cca_owners o ON o.id = c.owner_id
WHERE o.id='1'
AND IF c.max_redemptions != '0' THEN c.amount_generated >= c.max_redemptions
I can’t seem to get this working – I want to SELECT c.* where c.amount_generated >= c.max_redemptions only if c.max_redemptions doesn’t equal '0'.
I have other conditions I’d like to include in this query including: WHERE active='0' OR expiration_date > now()
Is ‘max_redemptions’ a number or a string?