このクエリがあります (3 つのサブクエリすべてが同じ行から異なる列を選択していることに注意してください)。product_bid
基本的に、行の横にある最大の日付で行を取得したいと考えていますproduct
。
SELECT
p.product_id,
p.product_title,
(SELECT b.bid_id FROM product_bids b WHERE b.bid_product_id=p.product_id ORDER BY b.bid_date DESC LIMIT 1) AS bid_id,
(SELECT b.bid_date FROM product_bids b WHERE b.bid_product_id=p.product_id ORDER BY b.bid_date DESC LIMIT 1) AS bid_date,
(SELECT b.bid_amount FROM product_bids b WHERE b.bid_product_id=p.product_id ORDER BY b.bid_date DESC LIMIT 1) AS bid_amount
FROM product p
WHERE p.product_auction_id=325
のPKを取得するためにサブクエリを1回実行しproduct_bids
、それに参加する方法(サブクエリの結果)またはこれを行うクリーンな方法はありますか?
補足: クエリ オプティマイザーはとにかくこれを認識し、重要性を下げますか?
ありがとう