mysql query ignoring part of WHERE statement
Hey guys, I've hound myself up against another wall... I have the following select statement ...
"SELECT campain_info.idCampaign, campain_info.couponTitle, campain_info.couponExcerpt, campain_info.couponDetails, campain_info.couponRetailPrice, campain_info.couponPrice, campain_info.amountSavings, campain_info.percentSavings, campain_info.expDate, campain_info.limitedQuantity AS 'Qty', campain_info.image, campain_info.localMarket, campain_info.tags, categories.idCategories, categories.categoryName, categories.categoryIcon, merchants.companyName, merchants.compnayWebsite, order_details.idDetails, Sum( CASE WHEN order_details.idDetails IS NOT NULL THEN 1 ELSE 0 END) AS 'Qty_Sold'
FROM campain_info INNER JOIN categories ON campain_info.categoryId = categories.idCategories INNER JOIN merchants ON campain_info.merchants_idMerchants = merchants.idMerchants LEFT OUTER JOIN order_details ON campain_info.idCampaign = order_details.campain_info_idCampaign
WHERE campain_info.expDate > CURDATE() AND campain_info.localMarket LIKE '$lm' AND campain_info.tags LIKE '$search' AND campain_info.limitedQuantity != 'Qty_Sold'
GROUP BY campain_info.idCampaign"
Everything works perfectly except that the final AND in the WHERE clause doesn't affect the return. For example, one of my campaigns has an available qty of 4, and even though the record set displays 4 has the qnty sold it is still returned in the record set. I've also tried > and <> in place of !=
Can you guys take a look at my select statement and see if I made an error OR if what i'm trying to accomplish can't be done this way?