I have the following code, but I don't know how to make it run faster.
SELECT lot.order as lot_order, lot.title as lot_title, lot.id as lot_id, lot.id_auction, IF ( (SELECT bid FROM bid WHERE lot.id = bid.id_lot ORDER BY bid.date DESC LIMIT 0,1) > lot.bid_minimum, (SELECT bid FROM bid WHERE lot.id = bid.id_lot ORDER BY bid.date DESC LIMIT 0,1), lot.bid_minimum ) AS bid, youtube, (SELECT path_image FROM lot_album WHERE lot_album.id_lot = lot.id AND order = 1) as image_featured FROM lot WHERE lot.excluded <> 1 AND lot.id_auction = 42 ORDER BY lot.order ASC
As you can see, I have the
IF to check if the value of the select is
> bid.minimum. The only way to improve this is check it on the programming language (PHP/.NET...) or there is another way?
- "lot_album" is a table where you can have lots of images, but also none. But only one image per lot will have order 1 so that image will be the "image_featured".