Q:

Write a mysql statement to get item id, item, price of the most expensive item

belongs to collection: MySQL Exercises

0

MySQL Get Maximum Value

Write a mysql statement to get item id, item, price of the most expensive item

Suppose the item table is -

+-----------+--------------+----------------+
| ITEM_ID   | ITEM         | PRICE          |
+-----------+--------------+----------------+
| 1001      | Book         | 1200           |
| 1002      | Pen          | 930            |
| 1003      | Bag          | 1430           |
| 1004      | Copy         | 1030           |
+-----------+--------------+----------------+

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

MySQL MAX() function returns maximum value in a set of values. It accepts one argument i.e. the expression and returns the highest value of the expression. This expression is the required parameter.

The following statement returns maximum price in set of price list of items.

SELECT  ITEM_ID, ITEM, PRICE
FROM ITEM
WHERE price=(SELECT MAX(price) FROM ITEM);

Output of the above code -

+---------+------+-------+
| ITEM_ID | ITEM | PRICE |
+---------+------+-------+
|    1003 | Bag  |  1430 |
+---------+------+-------+

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

MySQL Exercises

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a mysql statement to create a new user and s... >>
<< Write a mysql statement to get user, current date ...