EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL MIN()
 

PostgreSQL MIN()

Sohel Sayyad
Article bySohel Sayyad
EDUCBA
Reviewed byRavi Rathore

Updated May 18, 2023

PostgreSQL MIN()

 

 

Introduction to PostgreSQL MIN() Function

PostgreSQL supports various aggregate functions. The PostgreSQL MIN function is one of them, which is used to return the minimum value from the set of record values. We can use the PostgreSQL MIN function to find the minimum value for the column within the table. We need to pass the name of the column to the PostgreSQL MIN function specified in the SELECT SQL statement. The column we can pass to the PostgreSQL MIN function can have the data types such as string, number, or any other data type which can be compared. We can use the PostgreSQL MIN function with various clauses as well as with other aggregate functions as well.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax:

MIN (* | [DISTINCT] ALL | column_name)

Explanation:

  • *: This shows all of the rows.
  • column_name: This specifies the name of the column.
  • DISTINCT: It is used to show uniqueness and is an optional clause.
  • ALL: It specifies the default clause, and it is optional.

How does PostgreSQL MIN() Function Work?

  • The PostgreSQL MIN function is used for finding the minimum value for the specific column within the table, and it takes the name of the column as a parameter.
  • The column we can pass to the PostgreSQL MIN function can have the data types such as string, number, or any other data type which can be compared.
  • We can use the PostgreSQL MIN function with various clauses as well as other aggregate functions as well.

Examples

Let’s create a table named ‘furniture’ in order to understand the examples:

CREATE table furniture
(
furniture_id SERIAL PRIMARY KEY,
furniture_name VARCHAR (256) NOT null,
furniture_type VARCHAR (256) NOT null,
furniture_price int NULL
);

Now, insert some data in the furniture table in order to execute SQL statements.

INSERT INTO furniture (furniture_name,furniture_type,furniture_price)
VALUES
('Chair','Wood',2500),
('Chair','Plastic',2000),
('Chair','Rexine',3000),
('Table','Wood',5000),
('Table','Plastic',4000),
('Table','Rexine',5500),
('Sofa','Wood',10000),
('Sofa','Plastic',8000),
('Sofa','Rexine',8500),
('Bed','Wood',15000),
('Bed','Plastic',13000),
('Bed','Rexine',14000);

Illustrate the result of the above statement with the help of the following snapshot and the SELECT statement.

SELECT * FROM furniture;

Furniture Table

Example #1 – The PostgreSQL MIN() Function as a Level

Consider the following examples, which will show how to get the furniture with the minimum price from a table named ‘furniture’.

We can achieve this by writing a SQL statement in different ways as follows:

SELECT MIN(furniture_price) "Minimum price furniture"
FROM furniture;

Illustrate the result of the above statement by using the following snapshot:

Output-2

SELECT MIN(DISTINCT furniture_price) "Minimum price furniture"
FROM furniture;

Illustrate the result of the above statement by using the following snapshot:

Output - 3

SELECT MIN(ALL furniture_price) "Minimum price furniture"
FROM furniture;

Use the image below to demonstrate the outcome of the above statement:

PostgreSQL MIN()-2

Example #2 – WHERE Clause with the MIN() Function

Consider the following example, which will show how to get the furniture with the minimum price from the table named ‘furniture’ where the name of the furniture is Chair.

SELECT MIN(furniture_price) "Minimum price furniture"
FROM furniture6
WHERE furniture_name='Chair';

Use the image below to demonstrate the outcome of the above statement:

PostgreSQL MIN()-2

Example #3 – GROUP BY with the MIN() Function

Consider the following example for getting the minimum furniture price for each furniture type from the furniture table.

SELECT furniture_type, MIN(furniture_price) "Minimum price furniture"
FROM furniture
GROUP BY furniture_type;

Use the image below to demonstrate the outcome of the above statement:

PostgreSQL MIN()-3

Example #4 – HAVING CLAUSE with the MIN() Function

Consider the following example for getting the minimum furniture price for each furniture type whose minimum price is 2500 and below 13000 in the furniture table.

SELECT furniture_type, MIN(furniture_price) "Minimum price furniture"
FROM furniture
WHERE furniture_price < 13000
GROUP BY furniture_type
HAVING MIN(furniture_price) >= 2500;

Use the image below to demonstrate the outcome of the above statement:

PostgreSQL MIN()-4

Example #5 – GROUP BY and ORDER BY with the MIN() Function

Consider the following example for getting the furniture with a minimum furniture price is 2500 and below 13000 and the minimum furniture price for each furniture type as in descending order.

SELECT furniture_type, MIN(furniture_price) "Minimum price furniture"
FROM furniture
WHERE furniture_price < 13000
GROUP BY furniture_type
HAVING MIN(furniture_price) >= 2500
ORDER BY MIN(furniture_price) DESC;

Illustrate the result of the above statement by using the following snapshot:

PostgreSQL MIN()-5

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL MIN()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PostgreSQL Variables
  2. PostgreSQL GROUP BY
  3. Trunc() PostgreSQL
  4. PostgreSQL cluster

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW