开发者

a small SQL query problem with SELECT

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`开发者_Python百科
   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!


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`
GROUP BY `auction_id`
ORDER BY `auction_unixtime_expiration` ASC

Give that a try. Assuming that works, you can add your LIMIT on to the end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜