Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • SQL - Getting Started
  • What is SQL
  • Create Table
  • ALTER TABLE Statements
  • Rename Columns
  • Modify Column Type
  • Drop Columns
  • Rename Tables
  • Drop Tables
  • Insert Statement
  • Update Statement
  • Delete Statement
  • Truncate Statement
  • Merge Statement
  • Null Value
  • Select Query
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • SQL - Inner Join
  • SQL - Left Join
  • SQL - Right Join
  • SQL - Full Join
  • SQL - BETWEEN
  • SQL - IN
  • SQL - LIKE
  • SQL - INTERSECT
  • SQL - MINUS
  • SQL - UNION
  • SQL - UNION ALL
  • SQL - DISTINCT
  • SQL - ANY, SOME
  • SQL - ALL
  • SQL - AVG()
  • SQL - COUNT()
  • SQL - MAX()
  • SQL - MIN()
  • SQL - SUM()
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

SQL - MIN() Function

The MIN() function is an aggregate function that is used to find the smallest value of given column or expression. It can be applied on numeric, character or date values.

Syntax:

SELECT MIN(column_name) FROM table_name [WHERE condition] [GROUP BY];

For the demo purpose, we will use the following Employee and Department tables in all examples.

EmpIdFirstNameLastNameEmailSalaryDeptId
1JohnKing'[email protected]'2400010
2JamesBond480020
3NeenaKochhar'[email protected]'1500020
4LexDe Haan'[email protected]'900030
5AmitPatel6000030
6AbdulKalam'[email protected]'480040

The following selects the smallest salary from the Employee table.

SQL Script: MIN()
SELECT MIN(Salary) AS "Smallest Salary" FROM Employees;
Smallest Salary
4800

The following query gets all employees whose salary is the minimum.

SQL Script: MIN()
SELECT * FROM Employee WHERE Salary = (SELECT MIN(Salary) FROM Employee);
EmpIdFirstNameLastNameEmailSalaryDeptId
2JamesBond480020
6AbdulKalam'[email protected]'480040

The MIN() is an aggregate function, so it can be used in Group By queries. The following query gets Smallest salary in each department.

SQL Script: MIN() with Group By
SELECT DeptId, MIN(Salary) AS "Smallest Salary" FROM Employee GROUP BY DeptId;
DeptIdSmallest Salary
1024000
2015000
309000
404800

The MIN() function can be allpied on the varchar columns. The following selects the smallest FirstName from the Employee table.

SQL Script: MIN()
SELECT MIN(FirstName) AS "Smallest FirstName" FROM Employee;
Smallest FirstName
Lex
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.