sql >> Database teknologi >  >> RDS >> Mysql

SQL max() med indre joinforbindelser

Her er den:

SELECT i.title, bmax.amount, u.username
FROM itembid AS b
JOIN (SELECT item_id, MAX(amount) AS amount
      FROM itembid
      GROUP BY item_id) AS bmax
    ON b.item_id = bmax.item_id AND b.amount = bmax.amount
JOIN item AS i ON i.id = b.item_id
JOIN itembid AS ubid ON ubid.item_id = i.item_id
JOIN user AS u ON u.id = b.user_id
WHERE ubid.user_id = :current_user



  1. Hvorfor er PHPs mysql_-funktioner forældet?

  2. Mistet forbindelse til MySQL-server under forespørgsel

  3. MySQL UNIQUE-nøgle virker ikke

  4. Hvorfor giver denne MySQL-lagrede funktion andre resultater end at lave beregningen i forespørgslen?