一个关于 SELECT 的 SQL 查询小问题
SQL 查询仍然是我的弱点,所以这里我还有另一个 SQL 问题。
假设我有两个表:拍卖和出价。表拍卖包含我的拍卖,表出价包含每次拍卖的出价列表。
现在我选择这样的值:
SELECT
`auction_title`,
`auction_seo_title`,
`auction_description_1`,
`auction_unixtime_expiration`,
`auction_startPrice`,
MAX(`bids`.`bid_price`) as `bid_price`
FROM
`auctions`
LEFT JOIN `bids` ON `auctions`.`auction_id`=`bids`.`bid_belongs_to_auction`
ORDER BY
`auction_unixtime_expiration`
ASC
LIMIT 5
查询有效,但有一点问题:它仅选择那些在出价中具有至少一个对应值的拍卖强>表。这意味着,如果我有一个新的拍卖,但还没有出价,查询不会返回此拍卖,但我也想要它!
我相信对于任何具有至少高于平均 SQL 技能的人来说,这都是一个非常简单的问题。我希望有这样的人出现:) 提前致谢!
SQL queries are still my weakest point, so here I am with yet another SQL question.
Imagine I have two tables: auctions and bids. Table auctions contains my auctions and table bids contains the list of bids for each auction.
Now I'm selecting values like this:
SELECT
`auction_title`,
`auction_seo_title`,
`auction_description_1`,
`auction_unixtime_expiration`,
`auction_startPrice`,
MAX(`bids`.`bid_price`) as `bid_price`
FROM
`auctions`
LEFT JOIN `bids` ON `auctions`.`auction_id`=`bids`.`bid_belongs_to_auction`
ORDER BY
`auction_unixtime_expiration`
ASC
LIMIT 5
The query works, but it's got a little catch to it: It selects only those auctions, which have at least one corresponding value inside the bids table. That means that if I have a new auction, which has no bids yet, the query doesn't return this auction, but I want it too!
I believe this is a very simple problem for anyone with at least above average SQL skills. I hope someone like that comes around :) Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下。假设可行,您可以将 LIMIT 添加到末尾。
Give that a try. Assuming that works, you can add your LIMIT on to the end.