How to find most expensive items in sql with more than one most expensive item? How to find most expensive items in sql with more than one most expensive item? sqlite sqlite

How to find most expensive items in sql with more than one most expensive item?


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.


One way would be to use a join to fetch them all like so:

SELECT I.* FROM Items I JOIN   (SELECT MAX(price) AS maxprice FROM items) M   ON I.price=M.maxprice;


You can try this mate:

SELECT * FROM itemsWHERE itemID IN (   SELECT itemID FROM items   WHERE price IN (      SELECT MAX(price) FROM  items   ));  

or this

SELECT * FROM itemsWHERE price IN (   SELECT MAX(price) FROM items);