【发布时间】:2012-05-31 10:10:25
【问题描述】:
我有这个查询(请注意,所有 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
有没有办法进行一次子查询以获得product_bids 的 PK,然后加入(子查询的结果)或任何干净的方法?
旁注:查询优化器是否会认识到这一点,使其不那么重要?
谢谢
【问题讨论】: