I have more than one items with the highest price on my database and I would like to know how to return the most expensive items with the highest price on my database, without using LIMIT. I have tried using
SELECT MAX(price) FROM items
but it only returns one item with the highest price (I have two items with the highest price).
The schema of my database is
items (itemID: integer, description: string, price: integer)
This will work.
SET @p1 := (SELECT MAX(price) FROM items);
SELECT * FROM items WHERE price = @p1;
Using variables, p1 stores the maximum price from the table items and then uses the variable p1 in the following query to return all records which have that maximum price without limiting the number of records as you desired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With