我有这个查询
SELECT itemID, locationParentID, locationID, categoryParentID, categoryID, itemTitle, itemDetails, itemAttributes, itemPictures, itemFeatured, itemSpotlight, itemAdded
FROM items
WHERE locationID NOT IN
(SELECT locationID
FROM sites_locations
WHERE siteID != 2) AND items.siteID IN('1,2') AND itemStatus = '1'
AND itemAdded > '1356048000'
它工作正常但是当我执行这个查询时它失败了
SELECT itemID, locationParentID, locationID, categoryParentID, categoryID,
itemTitle, itemDetails, itemAttributes, itemPictures, itemFeatured, itemSpotlight, itemAdded FROM items
WHERE locationID NOT IN
(SELECT locationID
FROM sites_locations WHERE siteID != 2)
AND categoryID NOT IN (SELECT categoryID FROM sites_categories
WHERE siteID != 2) AND items.siteID IN('1,2') AND itemStatus = '1'
AND itemAdded > '1356048000'
这里的区别是我添加了子句
AND categoryID NOT IN(SELECT categoryID FROM sites_categories
WHERE siteID != ".$cfg['site']['siteID'].")
任何想法为什么这不起作用?
甚至更好的是加入查询来帮助优化它。
sites_categories 的表结构,数据在
项目的表结构,数据在
sites_locations 的表结构
位置的表结构,数据在
提前致谢。