結果集我有進行內SELECT
並返回結果作爲僞列的MySQL的語句。我想在我的WHERE
子句中使用這個僞列的結果。我現在的SQL語句如下所示:過濾器的MySQL結果通過的內選擇
SELECT
product.product_id,
product.range_id,
product.title,
product.image,
product.image_text,
product.friendly_url,
attribute.comfort_grade_id,
category.category_id,
category.category AS category_name,
category.friendly_url AS category_friendly_url,
(SELECT price_now FROM product_bedding_sizes AS size WHERE size.product_id = product.product_id ORDER BY size.price_now ASC LIMIT 1) AS price
FROM
products AS product
LEFT JOIN
categories AS category ON product.category_id = category.category_id
LEFT JOIN
product_bedding_attributes AS attribute ON product.product_id = attribute.product_id
$where
$order
LIMIT
?,?
不過,我得到運行查詢時出現以下錯誤信息:
#1054 - 未知列 '價格' 在 'where子句'
我怎樣才能解決這個問題,在我的WHERE
條款實際使用的price
價值?
做到這一點哪裏和你沒有共享這個變量。 – 2013-02-15 16:37:53
是的。無論是'$ where'和'$ order'變量構建的查詢之外,但'$ where'將包含類似'WHERE價格> 0 AND'price' <= 199'。 – 2013-02-16 11:12:34
你確定它的'price'列,而不是'price_now'因爲它甾體抗炎藥售價未知列 – 2013-02-16 11:15:08