SQL从4个类别获得产品,尽管我使用的是distinct??帮助
谢谢你的关注。 我从一个mdb抓取产品,该产品被标记为“热销”,但每个产品分为几个类别,每个类别显示4次!!有人能看到我把事情搞砸了吗? 非常感谢SQL从4个类别获得产品,尽管我使用的是distinct??帮助,sql,asp-classic,distinct,Sql,Asp Classic,Distinct,谢谢你的关注。 我从一个mdb抓取产品,该产品被标记为“热销”,但每个产品分为几个类别,每个类别显示4次!!有人能看到我把事情搞砸了吗? 非常感谢 pHotDeal = getUserInput(request.querystring("hotDeal"),2) mySql="SELECT DISTINCT products.idProduct, sku, description, price, visits, listPrice, length, width, height, smallIm
pHotDeal = getUserInput(request.querystring("hotDeal"),2)
mySql="SELECT DISTINCT products.idProduct, sku, description, price, visits, listPrice, length, width, height, smallImageUrl, sales, dateAdded, isBundleMain, rental, map, freeShipping, stock.stock, emailText, deliveringtime FROM products, stock, categories_products WHERE listHidden=0 AND active=-1 AND user1 is null AND idStore=" &pIdStore& " AND products.idStock=stock.idStock AND products.idProduct=categories_products.idProduct"
' hot deal
if pHotDeal<>"" then
mySQL=mySQL&" AND hotDeal=-1"
end if
pHotDeal=getUserInput(request.querystring(“hotDeal”),2)
mySql=“选择DISTINCT products.idProduct、sku、description、price、Visitions、listPrice、length、width、height、smallImageUrl、sales、dateAdded、isBundleMain、rental、map、freeShipping、stock.stock、emailText、deliveringtime FROM products、stock、categories\u产品,其中listHidden=0和active=-1且user1为空且idStore=“&pIdStore&“和产品。idStock=stock.idStock和产品。idProduct=categories\u products.idProduct”
“大买卖
如果是pHotDeal,那么
mySQL=mySQL&“和hotDeal=-1”
如果结束
为什么它不是“独特的”?:)
感谢所有人尝试:
Group By products.idProduct
您需要类别id才能获得1行。我发现了问题。“销售”按钮没有查询字符串“orderby”的值。似乎当我添加orderby值时,每个产品只显示一次。对不起!我知道我没有一点通过orderby选项,我认为这与此无关!
所以答案是-有一个空的查询字符串。
谢谢大家的帮助!!您检查了4行的每个字段是否相同了吗?@kevchadders是的,只有一个产品记录,它只是从4个不同的类别中引用的。这取决于您每个行有多少个类别的产品product@teamplayer每个产品有4个。表类别\u产品有two列idproduct和idcategory。因此,产品285被列出4次。idproduct-idcategory 285 116、285 83、285 95、285 117。这意味着当人们查看“桌子”、“餐具”、“椅子”、“餐厅”时“类别项目显示在所有中。您知道这很容易受到sql注入的影响,对吗?在Where part之后的末尾,当我转到没有任何类别的交易页面时。\u product.idcategory我正在尝试显示任何类别中标记为“hotdeal”的所有产品。发现问题!!!我添加到“销售”按钮的链接在查询字符串中没有orderby=。当我添加orderby时,似乎每个产品只显示一次。很抱歉我知道我一点也没有超过订单,我不认为这会影响订单!非常感谢你的帮助-1用于鼓励使用impillcit联接的sql反模式
SELECT DISTINCT products.idProduct,
sku,
description,
price,
visits,
listPrice,
LENGTH,
width,
height,
smallImageUrl,
sales,
dateAdded,
isBundleMain,
rental,
map,
freeShipping,
stock.stock,
emailText,
deliveringtime
FROM products, stock, categories_products
WHERE listHidden = 0
AND active = -1
AND user1 IS NULL
AND idStore = " &pIdStore& "
AND products.idStock = stock.idStock
AND products.idProduct = categories_products.idProduct
AND categories_product.idCategory = ??
GROUP BY products.idProduct