0

我正在为一个知名的购物车滚动我自己的功能。这是我的查询:

    SELECT d.product, d.product_id, p.price FROM cscart_product_descriptions AS d, cscart_product_prices AS p WHERE d.product_id IN (
SELECT product_id FROM cscart_products WHERE product_code IN (
SELECT product_id FROM cscart_range WHERE range_name IN (
SELECT range_name FROM cscart_range WHERE product_id = '0140885'
)))

当我从第一个选择中删除与 product_prices 相关的选择时,我得到了三个按预期返回的项目。当我使用包含的价格运行它时,我得到了大约 4,500 个结果。

我知道这是一个加入问题,我只是不确定如何纠正它。

干杯!

4

2 回答 2

1

它与 cscart_product_prices 表进行交叉连接..

你可以尝试这样的事情:

 select a.*,p.price from (
      SELECT d.product, d.product_id 
      FROM cscart_product_descriptions AS d 
      WHERE d.product_id IN (
         SELECT product_id FROM cscart_products WHERE product_code IN (
         SELECT product_id FROM cscart_range WHERE range_name IN (
         SELECT range_name FROM cscart_range WHERE product_id = '0140885'
         )))a
join cscart_product_prices AS p
on p.product_id=a.product_id
于 2012-10-01T09:49:23.910 回答
0

另外,试试这个查询与连接 -

SELECT
  d.product, d.product_id, p.price
FROM
  cscart_product_descriptions d
JOIN cscart_products p
  ON p.product_id = d.product_id 
JOIN cscart_range r1
  ON r1.product_id = p.product_code
JOIN cscart_range r2
  ON r2.range_name = p.range_name
WHERE r2.product_id = '0140885'
于 2012-10-01T10:01:13.250 回答