MAXVALUE
Example
Section titled “Example”CREATE TABLE employees ( id INT AUTO_INCREMENT, name VARCHAR(255), birth_date DATE, PRIMARY KEY (id)) AUTO_INCREMENT = 1 MAXVALUE 99999;Output
Section titled “Output”MySQL doesn’t provide direct output for MAXVALUE used in the above way. The MAXVALUE 99999 here just limits the id field to not exceed it.
Explanation
Section titled “Explanation”The MAXVALUE keyword in SQL specifies the maximum value a sequence of numbers can have. When we specify MAXVALUE for AUTO_INCREMENT in a MySQL CREATE TABLE statement, MySQL will stop generating new numbers for the id column once it reaches the specified MAXVALUE.
Example
Section titled “Example”CREATE TABLE example_table ( id SERIAL PRIMARY KEY, value INTEGER);
INSERT INTO example_table (value)VALUES (10), (20), (15), (30), (25);
SELECT MAX(value) AS max_value FROM example_table;Output
Section titled “Output” max_value----------- 30Explanation
Section titled “Explanation”In the given SQL code, we created a table example_table with id and value as columns. The id column is a serial type, meaning a unique number gets generated for each new record. We then inserted 5 rows in this table with different values for the value column. Finally, we used the MAX() function to retrieve the maximum value from the value column. The function returned 30 which is the maximum value among all values in the value column.
Example
Section titled “Example”SELECT MAX(salary) as max_salaryFROM employees;Output
Section titled “Output”+-------------+| max_salary |+-------------+| 12500 |+-------------+Explanation
Section titled “Explanation”MAX(salary) is an aggregate function that finds the maximum salary among all employees in the employees table. The column is aliased as max_salary for a clearer output display.