我有这个查询(请注意,所有 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
有没有办法做一次子查询以获得 PKproduct_bids
并加入它(子查询的结果)或任何干净的方式来做到这一点?
旁注:查询优化器是否会认识到这一点,使其不那么重要?
谢谢