How to use the COUNT() Function In MySQL
Query-1
CREATE TABLE product ( user_id INTEGER PRIMARY KEY, product_1 VARCHAR(50), product_2 VARCHAR(50), price INT ); INSERT INTO product (product_1, price) VALUES ('rice', 400); INSERT INTO product (product_2, price) VALUES ('grains', 600); SELECT COUNT(user_id) FROM product;
Output:
Query-2
Using the COUNT() function and counting float values.
CREATE TABLE floats ( user_id INTEGER PRIMARY KEY, float_val FLOAT ); INSERT INTO floats (float_val) VALUES (3.5); INSERT INTO floats (float_val) VALUES (2.1); INSERT INTO floats (float_val) VALUES (6.3); INSERT INTO floats (float_val) VALUES (9.9); INSERT INTO floats (float_val) VALUES (7.0); SELECT COUNT(*) FROM floats;
Output :
COUNT() Function in MySQL
Count() function in MySQL is used to find the number of indexes as returned from the query selected.
Features
- This function finds the number of indexes as returned from the query selected.
- It comes under Numeric Functions.
- It accepts only one parameter namely expression.
- This function ignores NULL values and doesnât count them.
Syntax:
COUNT(expression)
- Parameter values: This method accepts only one parameter as given below:
- Expression: A specified expression can either be a field or a string-type value.
- Returns: It returns the number of indexes as returned from the query selected.
Contact Us