Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SQL max() mit inneren Verknüpfungen

Hier ist es:

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