[MySQL]Join et max ne donne que une seule ligne de résultat

Join et max ne donne que une seule ligne de résultat [MySQL] - SQL/NoSQL - Programmation

Marsh Posté le 10-07-2009 à 13:49:59    

Salut,
 
voici ma requête :

Code :
  1. SELECT a.id, a.auction_type, a.initial_price, a.bid_type, a.picture, a.end_time, a.year, a.make, a.type,
  2. a.start_date AS cert_startdate, a.end_date AS cert_enddate, a.close_offer,
  3. b.name as currency,
  4. m.name as make,
  5. MAX(n.bid_price) as max_bid
  6. FROM jos_bid_auctions a
  7. LEFT JOIN jos_bid_currency b ON a.currency = b.id
  8. LEFT JOIN jos_bid_makes m ON m.id = a.make
  9. LEFT OUTER JOIN jos_bids n on n.id_offer = a.id
  10. WHERE a.published =1
  11. AND a.bid_type = '0'
  12. AND a.close_offer !=1
  13. AND a.end_date >= NOW()
  14. AND a.start_date <= NOW()
  15. ORDER BY a.end_date ASC
  16. LIMIT 5


Je voudrais retourner tous les max des bid_price pour chaque a.id
Et en fait je pense que la, on prend le max des bid_price pour tout le résultat ce qui ne renvoit qu'un seul résultat.
Y a-t-il un moyen de s'en sortir ?

Reply

Marsh Posté le 10-07-2009 à 13:49:59   

Reply

Marsh Posté le 10-07-2009 à 14:07:46    

Code :
  1. SELECT a.id, a.auction_type, a.initial_price, a.bid_type, a.picture, a.end_time, a.year, a.make, a.type,
  2. a.start_date AS cert_startdate, a.end_date AS cert_enddate, a.close_offer,
  3. b.name as currency,
  4. m.name as make,
  5. MAX(n.bid_price) as max_bid
  6. FROM jos_bid_auctions a
  7. LEFT JOIN jos_bid_currency b ON a.currency = b.id
  8. LEFT JOIN jos_bid_makes m ON m.id = a.make
  9. LEFT OUTER JOIN jos_bids n on n.id_offer = a.id
  10. WHERE a.published =1
  11. AND a.bid_type = '0'
  12. AND a.close_offer !=1
  13. AND a.end_date >= NOW()
  14. AND a.start_date <= NOW()
  15. GROUP BY a.id
  16. ORDER BY a.end_date ASC
  17. LIMIT 5


C'est mieux la ?


Message édité par Profil supprimé le 10-07-2009 à 14:09:41
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed