﻿ SQL - Find the name and price of the cheapest item(s)

# SQL Exercises: Find the name and price of the cheapest item(s)

## SQL Basic Select Statement: Exercise-30 with Solution

From the following table, write a SQL query to find the cheapest item(s). Return pro_name and, pro_price.

Sample table: item_mast

Sample Solution:

``````SELECT pro_name, pro_price
FROM item_mast
WHERE pro_price =
(SELECT MIN(pro_price) FROM item_mast);
``````

Output of the Query:

```pro_name	pro_price
ZIP drive	250.00
Mouse	    250.00```

Code Explanation:

The above query in SQL that selects the pro_name and pro_price columns from the table named 'item_mast' where the pro_price is equal to the minimum pro_price value in the table. As a result, the function returns the pro_name and the pro_price of the item in the table that has the lowest price in the table.

## Query Visualization:

Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous Python Exercise: Display the average price of the items for each company.
Next Python Exercise: Find the last name of all employees, without duplicates.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## SQL: Tips of the Day

MySQL select 10 random rows from 600K rows fast:

```SELECT name
FROM random AS r1 JOIN
(SELECT CEIL(RAND() *
(SELECT MAX(id)
FROM random)) AS id)
AS r2
WHERE r1.id >= r2.id
ORDER BY r1.id ASC
LIMIT 1
```

Ref: https://bit.ly/3GdCTM3

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook