0

tbl_dealinterest.Active この大きなクエリがあり、 =の結果を除外する必要があります'n'。そのテーブルに製品のエントリがない場合もあれば、エントリがあり、yに設定されている場合もあります。

これが大きな醜いクエリです:

SELECT tbl_product.id, tbl_productspecification.id AS specificationId,
                        tbl_product.ProductId, tbl_seller.CompanyName, tbl_product.ProductName, tbl_product.Description, mst_Categories.id AS 'Category',
                        tbl_productspecification.RetailPrice, tbl_productspecification.SalePrice,
                        tbl_product.image, tbl_productspecification.Discount, tbl_product.EndTime, tbl_product.Seller_Id, tbl_dealinterest.Active AS thumbsActive
                        FROM tbl_product
                        LEFT OUTER JOIN tbl_seller ON tbl_seller.SelId = tbl_product.Seller_Id
                        LEFT OUTER JOIN mst_Categories ON (mst_Categories.id = tbl_product.Category OR mst_Categories.id = tbl_product.SubCategory)
                        LEFT OUTER JOIN tbl_productspecification ON tbl_productspecification.ProductId = tbl_product.ProductId
                        LEFT OUTER JOIN mst_image ON mst_image.Product = tbl_product.ProductId
                        LEFT OUTER JOIN tbl_dealinterest ON tbl_dealinterest.ProductId = tbl_product.ProductId AND tbl_dealinterest.BuyerId = '$token' 
                        WHERE tbl_product.Active='y'
                        AND tbl_product.StartTime <= '".date("Y-m-d H:i:s")."'
                        AND tbl_product.EndTime > '".date("Y-m-d")." 06:00:00'
                        ".$subquery."
                        GROUP BY tbl_productspecification.ProductId";

提案をありがとう。

4

2 に答える 2

1
LEFT OUTER JOIN tbl_dealinterest ON (tbl_dealinterest.ProductId = tbl_product.ProductId 
    AND tbl_dealinterest.BuyerId = '$token' 
    AND tbl_dealinterest.Active<>'n')
于 2012-11-24T19:01:47.530 に答える
1
SELECT ...
WHERE tbl_product.Active='y'
AND (tbl_dealinterest.Active <> 'n' OR tbl_dealinterest.Active IS NULL)
...
于 2012-11-24T19:17:49.330 に答える