EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PostgreSQL MIN()

By Sohel SayyadSohel Sayyad

Home » Data Science » Data Science Tutorials » PostgreSQL Tutorial » PostgreSQL MIN()

PostgreSQL MIN()

Introduction to PostgreSQL MIN() Function

The 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 for finding the minimum value for the specific column within the table. We just 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.

Syntax:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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 it 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 a 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 of PostgreSQL MIN() Function

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;

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

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 furniture is Chair.

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

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

Popular Course in this category
PostgreSQL Course (2 Courses, 1 Project)2 Online Courses | 1 Hands-on Project | 7+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (2,979 ratings)
Course Price

View Course

Related Courses

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;

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

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;

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

PostgreSQL MIN()-4

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

Consider the following example for getting the furniture with 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

This is a guide to PostgreSQL MIN(). Here we discuss the introduction to PostgreSQL MIN() and its working along with different query examples for understanding better. You may also have a look at the following articles to learn more –

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

PostgreSQL Course (2 Courses, 1 Project)

2 Online Courses

1 Hands-on Project

7+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PostgreSQL Tutorial
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL log_statement
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

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

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

Special Offer - PostgreSQL Course (2 Courses, 1 Project) Learn More