Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

MYSQL LEAST Function

by suresh

MySQL LEAST is one of the Comparison Function, which returns the smallest argument. This MySQL LEAST function follows below shown rules:

  • If any of the argument is NULL, Least function returns NULL.
  • If all the arguments are integers, least finds the smallest or minimum number.
  • and, If we used strings as the arguments, this function finds the minimum or smallest string.

In this article, we show you how to find the smallest among given values in MySQL with example.

MySQL LEAST Syntax

The basic syntax of the Least in MySQL is as shown below:

LEAST(Value1, Value2......, ValueN);

MySQL LEAST Function Example 1

The following query shows multiple ways to use this MySQL Least function.

In the First statement, We used integers as arguments. The second statement finds the smallest decimal number. Next, it finds the smallest character in g, d, M, and Z.

SELECT LEAST(22, 5, 10);

SELECT LEAST(12.5, 3.2, 7.0, 2.5, 9.90);

SELECT LEAST('g', 'd', 'M', 'Z');
MySQL LEAST Function 1

Here, we used the combinations of integer, string, and decimal inside this Least function. Next, we used NULL as the MySQL argument.

SELECT LEAST('hello', 'hi', 'mysql');

SELECT LEAST(10, 10.0, '10');

SELECT LEAST(10, NULL, 20, 50);
MySQL LEAST Function 2

MySQL LEAST Function Example 2

In MySQL, you can use this function on column data. This example shows you how to use this Least function on a table.

In general, we use this Least function to find the smallest among multiple columns. The below query shows the smallest values among the Yearly Income column and Sales column for each employee Id.

SELECT EmpID,
FirstName,
      LastName,
      YearlyIncome,
      Sales, 
LEAST(YearlyIncome, SALES)
FROM `MySQL Tutorial`.customer
MySQL LEAST Function 3

The above Query was displayed Sales values as output because those are the smallest among two. This time we are comparing or finding the smallest among the Education and Occupation column values for each Employee ID.

SELECT EmpID, 
FirstName,
      LastName,
      Education,
      Occupation,
      YearlyIncome,
      Sales,
LEAST(Education, Occupation)
FROM `MySQL Tutorial`.customer
MySQL LEAST Function 4

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy