Learn how to use sql min function and sql max function, Remember, max and min function will only work on numeric column.
SQL Min and Max functions are in-built in SQL, very useful finding the minimum and maximum values for particular column that can help you get an insight of your data.
To get the maximum value of a integer/numeric column use the MAX()
function.
SELECT MAX(numericColumnName) FROM tableName; SELECT MAX(numericColumnName) FROM tableName GROUP BY ColumnName;
To get the minimum value of a integer/numeric column use the MIN()
function.
SELECT MIN(numericColumnName) FROM tableName; SELECT MIN(numericColumnName) FROM tableName GROUP BY ColumnName;
Suppose we want to find the max and min PointValue from the data below
tbCustomer --+----+----------+-----+-----------+----------+-------- | Id | Name | Code | City | PointValue | +----+----------+-----+-----------------+---------------- | 1 | Ajit | 0112 | Mumbai | 8054069773 | | 2 | Ropesh | 0247 | Delhi | 7852014758 | | 3 | Aniket | 0142 | Kolkata | 8852104758 | | 4 | Brinda | 0235 | Pune | 9954254758 | | 5 | Aman | 0478 | Raipur | 9652014758 | | 6 | Kajal | 0268 | Goa | 9452605758 | | 7 | Purnendu | 1403 | Bangalore | 9652720758 | +----+----------+-------+---------------+-------------+
Remember, to use the max, min function in SQL query, the column data type must be numeric / integer
select MIN(PointValue) from [dbo].[tbCustomer] select Max(PointValue) from [dbo].[tbCustomer]