0
$result = mysql_query("SELECT DISTINCT subscriberMaster.id,    
subscriberMaster.locationCodeID, subscriberMaster.firstName,
subscriberMaster.lastName, subscriberMaster.company, subscriberMaster.address,
subscriberMaster.address2, subscriberMaster.city, subscriberMaster.province,
subscriberMaster.postalCode, subscriberMaster.country,
subscriberMaster.numLabels
FROM subscriberMaster
JOIN commodityMaster ON commodityMaster.subscriberID = subscriberMaster.id AND
commodityMaster.commodityID IN (" . $commodityquery2 . ")
JOIN industryMaster ON industryMaster.subscriberID = subscriberMaster.id AND
industryMaster.industryID IN (" . $industryquery2 . ")
WHERE subscriberMaster.locationCodeID = $locationCodeID AND
subscriberMaster.province IN (" . $provincequery2 . ") AND
(subscriberMaster.deleted = 0) AND (subscriberMaster.expiryDate = '00-00-00')
OR (subscriberMaster.expiryDate > NOW()) ORDER BY $orderBy ASC");   

此查询中的所有内容都运行良好,直到我添加了第二个连接,它也与主表中的相同 id 匹配。Where 子句都可以正常工作,并且具有两个 ON 条件的第一个联接都有效。这似乎是第二个 JOIN 子句的问题。

基本上,subscribersMaster 是包含所有记录详细信息(地址、电话号码等)的主表。CommodityMaster 和 IndustryMaster 存储有关他们工作的行业和销售的商品的详细信息。

这是我回显查询时出现的结果。

SELECT DISTINCT subscriberMaster.id, subscriberMaster.locationCodeID,
subscriberMaster.firstName, subscriberMaster.lastName, subscriberMaster.company,
subscriberMaster.address, subscriberMaster.address2, subscriberMaster.city,
subscriberMaster.province, subscriberMaster.postalCode, subscriberMaster.country,
subscriberMaster.numLabels FROM subscriberMaster
JOIN commodityMaster ON commodityMaster.subscriberID = subscriberMaster.id
JOIN industryMaster ON industryMaster.subscriberID = subscriberMaster.id
WHERE subscriberMaster.locationCodeID = 1 AND commodityMaster.commodityID IN ('1',
'2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19',
'20','21','22','23','24','25','26','27','28','29','30','31','32','33') AND
industryMaster.industryID IN ('1','3','2') subscriberMaster.province IN
('Ontario') AND (subscriberMaster.deleted = 0) AND (subscriberMaster.expiryDate =
 '00-00-00') OR (subscriberMaster.expiryDate > NOW())
ORDER BY company ASC
4

0 回答 0