MySQL Articles

Page 87 of 355

How can we get some last number of characters from the data stored in a MySQL table's column?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 22-Jun-2020 219 Views

To get some last number of characters from the data stored in MySQL table’s column, we can use MySQL RIGHT() function. It will return the number of characters specified as it argument. We need to provide the name of the column, having the particular record from which we want to get last characters, as its first argument. To demonstrate it we are taking the example of a table named ‘examination_btech’ having the following examination details of students −mysql> Select * from examination_btech; +-----------+----------+--------+ | RollNo | Name | Course | +-----------+----------+--------+ | 201712001 ...

Read More

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

Sreemaha
Sreemaha
Updated on 22-Jun-2020 199 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)

Read More

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

Manikanth Mani
Manikanth Mani
Updated on 22-Jun-2020 211 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 find the index position of a string stored as a record in MySQL table's column?

Swarali Sree
Swarali Sree
Updated on 22-Jun-2020 205 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 MySQL SUM() function evaluates if it is used with SELECT statement that returns no matching rows?

Fendadis John
Fendadis John
Updated on 22-Jun-2020 269 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

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

Akshaya Akki
Akshaya Akki
Updated on 22-Jun-2020 296 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

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

karthikeya Boyini
karthikeya Boyini
Updated on 22-Jun-2020 3K+ 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 are the prerequisites for starting writing and using MySQL stored procedure?

Nikitha N
Nikitha N
Updated on 22-Jun-2020 338 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 to use MySQL Date functions with WHERE clause?

Ankith Reddy
Ankith Reddy
Updated on 22-Jun-2020 2K+ Views

By using the WHERE clause with any of the MySQL date functions, the query will filter the rows based on the condition provided in the WHERE clause. To understand it, consider the data from ‘Collegedetail’ table as followsmysql> Select * from Collegedetail; +------+---------+------------+ | ID | Country | Estb | +------+---------+------------+ | 111 | INDIA | 2010-05-01 | | 130 | INDIA | 1995-10-25 | | 139 | USA | 1994-09-25 | | 1539 | UK ...

Read More

How can we extract the Year and Month from a date in MySQL?

Monica Mona
Monica Mona
Updated on 22-Jun-2020 5K+ Views

It can be done with the following three ways in MySQLBy using EXTRACT() function For extracting YEAR and MONTH collectively then we can use the EXTRACT function. We need to provide the YEAR_MONTH as an argument for this function. To understand it, consider the following function using the data from table ‘Collegedetail’ −mysql> Select EXTRACT(YEAR_MONTH From estb) from collegedetail; +-------------------------------+ | EXTRACT(YEAR_MONTH From estb) | +-------------------------------+ | 201005 | | ...

Read More
Showing 861–870 of 3,547 articles
« Prev 1 85 86 87 88 89 355 Next »
Advertisements