I have two tables, one called items and one called bids. Bids contains a bunch of bids with an item_id. I am trying to get all the information on the item with the associated highest bid.
I tried doing something like
SELECT * FROM items JOIN bids ON items.id=bids.item_id GROUP BY item_id
However that seems to return the first bid, not the highest.
How could I get the highest?
You need to use a subquery to discover the maximum bid value, then join that with your existing query to obtain all of the desired output data. Assuming that the bid value is in a column called
value, and that the PK of thebidstable is a column calledid:If there are multiple bids of the maximum amount, this query will return all of them.