Found 4219 Articles for MySQLi

How can I customize the output of MySQL SUM() function to 0 instead of NULL when there are no matching rows?

Arjun Thakur
Updated on 22-Jun-2020 05:20:30

160 Views

As we know that the SUM() function returns NULL if there is no matching row but sometimes we want it to return zero instead of NULL. For this purpose, we can use the MySQL COALESCE() function which accepts two arguments and returns the second argument if the first argument is NULL, otherwise, it returns the first argument. To understand the above concept, consider an ‘employee_tbl’ table, which is having the following records −mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id   | name | work_date  | daily_typing_pages | +------+------+------------+--------------------+ | 1    | John | 2007-01-24 |       ... Read More

How can we see the list of stored procedures and stored functions in a particular MySQL database?

Sreemaha
Updated on 22-Jun-2020 05:22:34

181 Views

We can see the list of the stored procedure and stored functions in a particular database by using the following query on INFORMATION_SCHEMA.ROUTINES as follows −mysql> SELECT ROUTINE_TYPE, ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'query'; +--------------+--------------+ | ROUTINE_TYPE | ROUTINE_NAME | +--------------+--------------+ | PROCEDURE    | allrecords   | | FUNCTION     | Hello        | +--------------+--------------+ 2 rows in set (0.04 sec)The above query returns the procedure named ‘allrecords’, and function named ‘Hello’ which are stored in the database named ‘query’.

How can we use MySQL SUM() function with HAVING clause?

karthikeya Boyini
Updated on 22-Jun-2020 05:06:51

2K+ Views

By using MySQL SUM() function with the HAVING clause, it filters the result based on a specific condition given after the HAVING clause. To understand the above concept, consider an ‘employee_tbl’ table, which is having the following records −mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id   | name | work_date  | daily_typing_pages | +------+------+------------+--------------------+ | 1    | John | 2007-01-24 |        250         | | 2    | Ram  | 2007-05-27 |        220         | | 3    | Jack | 2007-05-06 |       ... Read More

What is the benefit of using MySQL SUM() function with GROUP BY clause?

Akshaya Akki
Updated on 22-Jun-2020 05:08:37

135 Views

When we use MySQL SUM() function with GROUP BY Clause the SUM() function evaluates the sum for every group specified in the GROUP BY clause. The benefit of using SUM() with GROUP BY clause is that we can easily find the total of a particular group. To understand the above concept, consider an ‘employee_tbl’ table, which is having the following records −mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id   | name | work_date  | daily_typing_pages | +------+------+------------+--------------------+ | 1    | John | 2007-01-24 |        250         | | 2    | Ram ... Read More

What are the advantages and disadvantages of using MySQL stored procedures?

Nitya Raut
Updated on 22-Jun-2020 05:19:43

2K+ Views

There are numerous advantages and disadvantages of using MySQL stored procedures which are as follows −MySQL Stored Procedure AdvantagesFollowings are the advantages of using MySQL Stored Procedures −Increasing the performance of applications − As we know that after creating the stored procedure it is compiled and stored in the database. But MySQL implements stored procedures slightly different which helps in increasing the performance of the applications. MySQL stored procedures are compiled on demand. After compiling a stored procedure, MySQL puts it into a cache. And MySQL maintains its own stored procedure cache for every single connection. If an application uses ... Read More

What are the prerequisites for starting writing and using MySQL stored procedure?

Nikitha N
Updated on 22-Jun-2020 05:06:06

184 Views

We must have the following prerequisites before starting writing and using MySQL stored procedures −MySQL VersionAs we know that MySQL 5 introduced stored procedures, hence first of all we need to check for the version of MySQL before staring writing and using stored procedures. It can be done with the following query −mysql> Select VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.20    | +-----------+ 1 row in set (0.10 sec)Privileges for the current userActually, CREATE PROCEDURE and CREATE FUNCTION require the CREATE ROUTINE privilege. By default, MySQL automatically grants the ALTER ROUTINE and EXECUTE privileges to the routine creator. ... Read More

How MySQL SUM() function evaluates if it is used with SELECT statement that returns no matching rows?

Fendadis John
Updated on 22-Jun-2020 05:09:31

118 Views

When MySQL SUM() function used with SELECT statement that returns no matching rows then there is nothing to evaluate and it returns NULL as output. Sometimes, we thought it must return 0 as output but 0 is a number itself and for no matching rows it not significant to return 0 hence it returns NULL. To understand the above concept, consider an ‘employee_tbl’ table, which is having the following records −mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id   | name | work_date  | daily_typing_pages | +------+------+------------+--------------------+ | 1    | John | 2007-01-24 | 250         ... Read More

How can we find the index position of a string stored as a record in MySQL table’s column?

Swarali Sree
Updated on 22-Jun-2020 05:10:22

101 Views

We can use FIELD() function to find the index position of a string stored as a record in MySQL table’s column. To demonstrate it we are using the table named ‘websites’ having the following dataExamplemysql> Select * from websites; +----+---------------+------------------------+ | Id | Purpose       | Webaddress             | +----+---------------+------------------------+ | 1  | For tutorials | www.tutorialspoint.com | | 2  | For searching | www.google.co.in       | | 3  | For email     | www.gmail.com          | +----+---------------+------------------------+ 3 rows in set (0.00 sec)Now, suppose if we ... Read More

How can we use MySQL SUM() function to calculate the sum of only dissimilar values of the column?

Manikanth Mani
Updated on 22-Jun-2020 05:12:02

80 Views

For calculating the sum of only dissimilar values of the column we can use ‘DISTINCT’ keyword along with the name of the column. To understand SUM() function for dissimilar values, consider an ‘employee_tbl’ table, which is having the following records −mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id   | name | work_date  | daily_typing_pages | +------+------+------------+--------------------+ | 1    | John | 2007-01-24 | 250                | | 2    | Ram  | 2007-05-27 | 220                | | 3    | Jack | 2007-05-06 | 170 ... Read More

How can we get only the name having no other details about the tables in MySQL database?

Sreemaha
Updated on 22-Jun-2020 05:12:48

77 Views

With the help of SHOW TABLES command, we can get only the name having no other information about the tables. For example, we can see the list of tables in a database named tutorial as follows −mysql> show tables; +--------------------+ | Tables_in_tutorial | +--------------------+ | student            | +--------------------+ 1 row in set (0.00 sec)

Advertisements