Found 4219 Articles for MySQLi

What MySQL COUNT() function returns if there are some NULL values stored in a column also?

Jai Janardhan
Updated on 22-Jun-2020 05:13:36

96 Views

When we use MySQL COUNT() function to count the values stored in a column which also stored some NULL values then MySQL ignores the NULL and returns the result for only non-NULL values. To understand it, we are using the data, as follows, from table ‘Employee’ −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | 20000  | | 6  | ... Read More

How can we add a time interval to date stored in a column of MySQL table?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

185 Views

MySQL ADDTIME() function can be used to add a time interval in the data stored in a column of the table. The syntax of this function is ADDTIME(date, ‘expression unit’). It can be demonstrated by following the example which uses the data from table ‘collegedetail’. mysql> Select estb, ADDTIME(estb, '05:04:25')AS 'Date with time' From collegedetail WHERE ID = 111; +------------+---------------------+ | estb | Date with time | +------------+---------------------+ | 2010-05-01 | 2010-05-01 05:04:25 | +------------+---------------------+ 1 row in set (0.02 sec) Here, ‘estb’ is a column of table ‘collegedetail’ having the date as values.

How can we add day/s in the date stored in a column of MySQL table?

Alankritha Ammu
Updated on 22-Jun-2020 04:57:37

125 Views

Two functions can be used for this purpose and in both the functions we need to provide column name as an argument along with INTERVAL keyword. The functions are as follows −DATE_ADD() functionThe syntax of this function is DATE_ADD(date, INTERVAL expression unit). It can be demonstrated by following the example which uses the data from table ‘collegedetail’ −mysql> Select estb, DATE_ADD(estb, INTERVAL 10 DAY) from collegedetail; +------------+---------------------------------+ | estb | DATE_ADD(estb, INTERVAL 10 DAY)       | +------------+---------------------------------+ | 2010-05-01 | 2010-05-11                      | | 1995-10-25 | 1995-11-04     ... Read More

How to check table status of the tables in a particular MySQL database?

varma
Updated on 22-Jun-2020 04:56:12

293 Views

We can check the status of tables in a database with the help of show table status statement. For example, in the database named tutorial, by executing this statement we can get the status of tables as follows −mysql> show table status \G*************************** 1. row ***************************            Name: student          Engine: InnoDB         Version: 10      Row_format: Compact            Rows: 0  Avg_row_length: 0     Data_length: 16384 Max_data_length: 0    Index_length: 0       Data_free: 7340032  Auto_increment: NULL     Create_time: 2017-10-24 09:34:29   ... Read More

While running MySQL statements in batch mode, how can we print, along with output, which statements are getting executed?

Srinivas Gorla
Updated on 11-Feb-2020 08:30:25

192 Views

By using –v option in batch mode, the MySQL statements can be printed along with output. For example, after running the same query in batch mode with –v option we will get the statement printed along with output.C:\Program Files\MySQL\bin>mysql -u root -p gaurav < hh.sql -v Enter password: ***** -------------- select * from hh -------------- id 1 2It is showing the statement select * from hh which is written in the file hh.sql.

How to get the MySQL interactive output format in batch mode also?

usharani
Updated on 22-Jun-2020 04:59:20

268 Views

We can get the MySQL output format in batch mode with the help of –t option. For example, after running the same query in batch mode with –t option we will get the output like interactive format.ExampleC:\Program Files\MySQL\bin>mysql -u root -p gaurav < hh.sql -t Enter password: *****Output+------+ | id   | +------+ | 1    | | 2    | +------+

What would be the difference between default output format when running MySQL in batch mode or interactively?

Abhinanda Shri
Updated on 22-Jun-2020 04:58:48

58 Views

The default MySQL output would be different if we will run the same query interactively or in batch mode. For example, if we will run the query select * from hh interactively then following would be a format of output −mysql> select * from hh; +------+ | id   | +------+ |  1   | |  2   | +------+ 2 rows in set (0.01 sec)On the other hand, if we will run the same query in batch mode then following would be the format of output −C:\Program Files\MySQL\bin>mysql -u root -p gaurav < hh.sql Enter password: ***** id 1 2

How can we run MySQL statements in batch mode?

varun
Updated on 22-Jun-2020 05:00:18

288 Views

We need to create a .sql file for running MySQL in batch mode. This file will contain the MySQL statements. Suppose I have hh.sql file in which I have written the statement select * from hh. With the help of the following command, we can run this file in batch mode −ExampleC:\Program Files\MySQL\bin>mysql -u root -p gaurav < hh.sql Enter password: *****Outputid 1 2Here Gaurav is the database name that contains the table hh. Whenever you’ll run this command it will ask for the password and then give the output.

Do we require any authentication for login into MySQL command line tool?

Prabhas
Updated on 20-Jun-2020 13:52:19

102 Views

Yes, we require authentication for login into MySQL command line tool. For example, if we are trying to log in from windows command line then it will prompt for the password every time. The command for login is as follows −C:\Program Files\MySQL\bin>mysql -u root -p Enter password: *****

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

Monica Mona
Updated on 22-Jun-2020 05:01:52

4K+ 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 | |                        199510 | |             ... Read More

Advertisements