andwise — 2010-02-10T16:28:03-05:00 — #1
I know that the following will return the highest price in the 'price' column:
How can I also get it to show the corresponding item with the max price?
I have played around with it but can't figure it out.
r937 — 2010-02-10T18:09:56-05:00 — #2
here's a quick way:
SELECT item, price
ORDER BY price DESC LIMIT 1
spacephoenix, i think there might have been only one table involved in this question
spacephoenix — 2010-02-10T17:03:08-05:00 — #3
Assuming that your items table is called "items" and that the item name field is called "name"
MAX(orders.price) AS highest_price
, items.name AS item
items_ordered AS orders
items.item_id = orders.item_id
spacephoenix — 2010-02-10T18:41:27-05:00 — #4
I did wonder if it was just one table. Andwise, is it one table or is it two tables?
andwise — 2010-02-10T19:50:10-05:00 — #5
It is one table. Sorry for not specifying. I never considered using the limit function.
Thanks for your help.