Aggregate Functions
Aggregate Functions
• Syntax:
• Select min(aggregate expression) from table name
MIN()
• MIN()
•
• mysql> select min(fees) from student;
• +-----------+
• | min(fees) |
• +-----------+
• | 3200 |
• +-----------+
• 1 row in set (0.00 sec)
COUNT AND COUNT(*)
• Count function returns the count of an expression
• Syntax:
• Select count (aggregate_expression) from tables
• This is the column or expression whose non null values will be counted.
DIFFERENCE BETWEEN COUNT AND COUNT (*)
• COUNT(expression)
• The COUNT(expression) returns the number of rows that do not contain NULL
values as the result of the expression.
• COUNT(DISTINCT expression)
• The COUNT(DISTINCT expression) returns the number of distinct rows that do
not contain NULL values as the result of the expression.
COUNT(*)
• mysql> select count(*) from student;
• +----------+
• | count(*) |
• +----------+
• | 11 |
• +----------+
• 1 row in set (0.00 sec)
COUNT(FIELD NAME)
• mysql> select count(stid) from student;
• +-------------+
• | count(stid) |
• +-------------+
• | 10 |
• +-------------+
• 1 row in set (0.00 sec)
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]
DISTINCT
• The SQL DISTINCT keyword is used in conjunction with the SELECT statement
to eliminate all the duplicate records and fetching only unique records.
Syntax:
SELECT DISTINCT column1, column2,.....columnN
FROM table_name
WHERE [condition]
DISTINCT
• mysql> select distinct(fees) from student;
• +------+
• | fees |
• +------+
• | 9000 |
• | 8000 |
• | 3200 |