Found 4381 Articles for MySQL

How can we use MySQL POWER() function with the column’s data values?

Samual Sam
Updated on 20-Jun-2020 13:09:17

143 Views

If we want to use POWER() function with column’s data values then the first argument i.e. the base would be the name of the column and the second argument i.e. the exponent would be as specified by us. To understand it considers a table ‘Employee’ having the following records −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | 20000  | ... Read More

In MySQL, how to raise a number to the power of another number?

Govinda Sai
Updated on 20-Jun-2020 13:09:47

343 Views

POWER() function is used to raise a number to the power of another number. POW() is the synonym of POWER() function. In these functions, the first arguments work as the base and the second argument works as the exponent. SyntaxPOWER(M, N)  Here, M is the number which is the base of exponentiation. N is the number which is the exponent of exponentiation.Examplemysql> Select POWER(2,3),POW(2,3); +------------+----------+ | POWER(2,3) | POW(2,3) | +------------+----------+ |          8 |        8 | +------------+----------+ 1 row in set (0.00 sec)

What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL TRUNCATE() function?

Sravani S
Updated on 10-Feb-2020 10:39:10

394 Views

If we specify the negative value of the second argument then the digits before the decimal point would be deleted without rounded off. The number of digits to be deleted depends upon the value of the negative second argument. Following examples will demonstrate the change, depending upon the negative value of the second argument, in the output of TRUNCATE() function.  mysql> Select TRUNCATE(1789.456, -1); +-----------------------+ | TRUNCATE(1789.456, -1) | +-----------------------+ |                  1780 | +-----------------------+ 1 row in set (0.00 sec)  The query above returns 1780 because the first digit before the decimal point ... Read More

What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL ROUND() function?

Priya Pallavi
Updated on 10-Feb-2020 10:37:50

1K+ Views

If we specify the negative value of the second argument then the digits before the decimal point would be deleted and rounded off. The number of digits to be deleted depends upon the value of the negative second argument. Following examples will demonstrate the change, depending upon the negative value of the second argument, in the output of ROUND() function.mysql> Select ROUND(1789.456, -1); +--------------------+ | ROUND(1789.456, -1) | +--------------------+ |               1790 | +--------------------+ 1 row in set (0.00 sec)  The query above returns 1790 because the first digit (which is to be deleted ... Read More

What is the significant difference between MySQL TRUNCATE() and ROUND() function?

Srinivas Gorla
Updated on 20-Jun-2020 13:11:16

5K+ Views

The TRUNCATE() function is used to return the value of X truncated to D number of decimal places. If D is 0, then the decimal point is removed. If D is negative, then D number of values in the integer part of the value is truncated. Consider the following example –mysql> Select TRUNCATE(7.536432, 2); +----------------------+ | TRUNCATE(7.536432, 2) | +----------------------+ |                 7.53 | +----------------------+ 1 row in set (0.00 sec)The ROUND() function returns X rounded to the nearest integer. If a second argument, D, is supplied, then the function returns X rounded ... Read More

How can I fetch the value of REPLACE() function in the column name of our choice?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

117 Views

For fetching the values of REPLACE() function in our choice column name, we need to use the keyword ‘AS’ with REPLACE() function. Example mysql> Select Name, REPLACE(Name, 'G','S') AS Name_Changed from student Where Subject = 'Computers'; +--------+--------------+ | Name | Name_Changed | +--------+--------------+ | Gaurav | Saurav | | Gaurav | Saurav | +--------+--------------+ 2 rows in set (0.00 sec) The query above will give the result set of REPLACE() function in column name of our choice ‘Name_Changed’ which is given after keyword ‘AS’.

In MySQL, how CEILING() and FLOOR() functions are different from ROUND() function?

Govinda Sai
Updated on 20-Jun-2020 13:12:04

7K+ Views

The CEILING() function returns the smallest integer value that is not smaller than X. Consider the following example –mysql> Select CEILING(3.46); +---------------+ | CEILING(3.46) | +---------------+ |             4 | +---------------+ 1 row in set (0.00 sec)   mysql> Select CEILING(-6.43); +----------------+ | CEILING(-6.43) | +----------------+ |             -6 | +----------------+ 1 row in set (0.02 sec)The FLOOR() function returns the largest integer value that is not greater than X. Consider the following example –mysql> Select FLOOR(-6.43); +--------------+ | FLOOR(-6.43) | +--------------+ |           -7 ... Read More

How MySQL LENGTH() function measures the string length?

Sravani S
Updated on 20-Jun-2020 13:13:11

276 Views

MySQL LENGTH() function measures the string length in ‘bytes’ which means that it is not multibyte safe. The difference of the result between multi-byte safe functions, like CHAR_LENGTH() or CHARACTER_LENGTH(), and LENGTH() function especially relevant for Unicode, in which most of the characters are encoded in two bytes or relevant for UTF-8 where the number of bytes varies. For example, if a string contains four 2-bytes characters then LENGTH() function will return 8, whereas CHAR_LENGTH() or CHARACTER_LENGTH() function will return 4. It is demonstrated in the example below −Examplemysql> Select LENGTH('tutorialspoint'); +--------------------------+ | LENGTH('tutorialspoint') | +--------------------------+ |       ... Read More

How can we get randomly different set of rows or values each time from MySQL table?

Arushi
Updated on 20-Jun-2020 13:14:05

125 Views

When we use RAND() function along with both ORDER BY and LIMIT clause in a query, MySQL returns the different set of rows or values each time. To understand it considers a table ‘Employee’ having the following records −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | 20000  | | 6  | Mohan  | 30000  | | 7  | Aryan ... Read More

How can we generate the same sequence of random numbers in MySQL?

Vikyath Ram
Updated on 20-Jun-2020 13:01:46

256 Views

When invoked with an integer argument, RAND( ) uses that value to seed the random number generator. Each time you seed the generator with a given value, RAND( ) will produce the same sequence of random numbers. Following example will demonstrate it −Examplemysql> Select RAND(1), RAND(1), Rand(1); +---------------------+---------------------+---------------------+ | RAND(1)             | RAND(1)             | Rand(1)             | +---------------------+---------------------+---------------------+ | 0.40540353712197724 | 0.40540353712197724 | 0.40540353712197724 | +---------------------+---------------------+---------------------+ 1 row in set (0.00 sec)

Advertisements