MySQL Articles

Page 119 of 355

What MySQL TRIM() function returns if 1st argument(i.e. BOTH, LEADING, TRAILING) is not specified?

Ayyan
Ayyan
Updated on 07-Feb-2020 113 Views

By default MySQL will assume the argument BOTH if the 1st argument is not specified in TRIM() function. Following example will demonstrate it.Examplemysql> SELECT TRIM('A' FROM 'ABCDAEFGAA'); +-----------------------------+ | TRIM('A' FROM 'ABCDAEFGAA') | +-----------------------------+ | BCDAEFG                     | +-----------------------------+ 1 row in set (0.00 sec)The above result set shows that when we did not specify 1st argument then MySQL returns the output by assuming BOTH as the 1st argument of TRIM() function.

Read More

What would be the output of MySQL SUM() function if a column having no values has been passed as its argument?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 07-Feb-2020 165 Views

When MySQL SUM() function got a column, having no values, as an argument then it will return NULL, rather than 0, as output. The column can be of any data type. Following the example, using a table named ‘social’ having only one column named ‘id’ with no values, will illustrate itExamplemysql> Describe Social; +-------+-------------+------+-----+---------+-------+ | Field | Type        | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Id    | int(11)     | YES  |     |   NULL  |       | | Name  | varchar(20) | YES  |     ...

Read More

How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?

Paul Richard
Paul Richard
Updated on 07-Feb-2020 3K+ Views

When MySQL SUM() function got a column, having no values, an argument then it will return NULL, rather than 0, as output. But if we want to customize this output to show 0 as output then we can use 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 illustrate it, we are taking the example of ‘Tender’ table having the following data −mysql> Select * from tender; +----+---------------+--------------+ | Sr | CompanyName   | Tender_value | +----+---------------+--------------+ | 1  | Abc Corp.   ...

Read More

How MySQL SUM() function evaluates if it got the column, having character data type, as its argument?

Chandu yadav
Chandu yadav
Updated on 07-Feb-2020 200 Views

MySQL SUM() function will return 0, rather than NULL, along with a warning on getting the character type column as its argument. Following example using data from table named ‘Social’ will illustrate it −Examplemysql> Select * from Social; +------+-------+ | Id   | Name  | +------+-------+ | 100  | Rahul | +------+-------+ 1 row in set (0.00 sec) mysql> Select SUM(Name) From Social; +-----------+ | SUM(Name) | +-----------+ | 0         | +-----------+ 1 row in set, 1 warning (0.00 sec)

Read More

How can we export data to a CSV file whose filename name contains timestamp at which the file is created?

Nishtha Thakur
Nishtha Thakur
Updated on 07-Feb-2020 601 Views

Sometimes we need to export data into a CSV file whose name has a timestamp at which that file is created. It can be done with the help of MySQL prepared statement. To illustrate it we are using the following example −ExampleThe queries in the following example will export the data from table ‘student_info’ to the CSV file having a timestamp in its name.mysql> SET @time_stamp = DATE_FORMAT(NOW(), '_%Y_%m_%d_%H_%i_%s'); Query OK, 0 rows affected (0.00 sec) mysql> SET @FOLDER = 'C:/mysql/bin/mysql-files'; Query OK, 0 rows affected (0.00 sec) mysql> SET @FOLDER = 'C:/mysql/bin/mysql-files/'; Query OK, 0 rows affected ...

Read More

How can we export data to a CSV file along with columns heading as its first line?

Krantik Chavan
Krantik Chavan
Updated on 07-Feb-2020 243 Views

For adding the column values we need to use UNION statement. It can be demonstrated with the help of the following example −ExampleIn this example data from student_info will be exporting to CSV file. The CSV file will have the first line as the name of the columns.mysql>(SELECT 'id', 'Name', 'Address', 'Subject')UNION(SELECT id, Name, Address, Subject From student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student_25.CSV' FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY '\r'); Query OK, 7 rows affected (0.04 sec)After executing the above query MySQL creates Student_25.CSV file which have the following values −id;    "Name";     ...

Read More

How MySQL evaluates if we export the data to CSV file from a table which contains a NULL value(s)?

Daniol Thomas
Daniol Thomas
Updated on 07-Feb-2020 398 Views

If we export the data from a table having NULL values then MySQL will store \N in CSV file for the record MySQL table having NULL values. It can be illustrated with the help of the following example −ExampleSuppose if we want to export the values of the table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | ...

Read More

How can we store any other value than N in CSV file if we export the data to CSV file from a table which contains a NULL value(s)?

Nancy Den
Nancy Den
Updated on 07-Feb-2020 288 Views

If we want to store any other value than \N in CSV file on exporting the data to CSV file from a table which contains NULL value(s) then we need to replace \N values with other value by using IFNULL statement. To illustrate it we are taking the following example −ExampleSuppose if we want to export the values of the table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | ...

Read More

How can we tackle MySQL error 'ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement' while importing or exporting the data?

Abhinaya
Abhinaya
Updated on 07-Feb-2020 1K+ Views

MySQL throws this error because of the two reasons, either no directory is specified under --secure--file--priv variable or we are giving the wrong path in our query while importing or exporting the data. To tackle this error we must have to check the value of –secure—file—priv variable by following query −mysql> Select @@global.secure_file_priv; +---------------------------+ | @@global.secure_file_priv | +---------------------------+ | C:\mysql\bin\mysql-files\ | +---------------------------+ 1 row in set (0.00 sec)We can see there is path under secure_file_priv variable and all the files would be created under this directory when we export the data.But, if the above command shows NULL as result then ...

Read More

Which MySQL function returns a specified number of characters of a string as output?

Ayyan
Ayyan
Updated on 06-Feb-2020 529 Views

MySQL returns a specified number of characters of a string with the help of LEFT() and RIGHT() functions.MySQL LEFT() function will return the specified number of characters from the left of the string.SyntaxLEFT(str, length)Here str is the string from which a number of characters would be returned and the length is an integer value which specifies how many characters to be returned.Examplemysql> Select LEFT('My Name is Ram', 7); +---------------------------+ | LEFT('My Name is Ram', 7) | +---------------------------+ | My Name                   | +---------------------------+ 1 row in set (0.00 sec)MySQL RIGHT() function will ...

Read More
Showing 1181–1190 of 3,547 articles
« Prev 1 117 118 119 120 121 355 Next »
Advertisements