Found 6702 Articles for Database

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

67 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

6K+ 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

179 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

71 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

157 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)

How can I use RAND() function in an ORDER BY clause to shuffle MySQL set of rows?

Paul Richard
Updated on 20-Jun-2020 13:02:41

296 Views

When we use MySQL ORDER BY clause with RAND() function then the result set would have the shuffled set of rows. In other words, the result set would be in a random order. 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  | ... Read More

I am calling RAND() function two times in the same query then will it generate same random number two times or will it generate two different random numbers?

George John
Updated on 30-Jul-2019 22:30:21

216 Views

We know that MySQL RAND() returns a random floating point value between the range of 0 and 1. It will generate two different random numbers if we will call the RAND() function, without seed, two times in the same query. Following example will make it clearer − Example mysql> Select RAND(), RAND(), Rand(); +--------------------+-------------------+--------------------+ | RAND() | RAND() | Rand() | +--------------------+-------------------+--------------------+ | 0.9402844448949066 | 0.911499003797303 | 0.7366417150354402 | +--------------------+-------------------+--------------------+ 1 row in set (0.00 sec) The above result set shows that RAND() function will generate different random number every time we call it.

How can we check for NULL in a MySQL query?

Kumar Varma
Updated on 20-Jun-2020 13:03:23

175 Views

With the help of IS NULL operator, we can check for NULL in a MySQL query. We cannot use = (comparison operator) because as we know that NULL is not a value. Following example using the data from ‘employee’ table will exhibit it −Examplemysql> Select * from Employee WHERE Salary IS NULL; +----+-------+--------+ | ID | Name  | Salary | +----+-------+--------+ | 7  | Aryan | NULL   | | 8  | Vinay | NULL   | +----+-------+--------+ 2 rows in set (0.00 sec)The query above use IS NULL operator and produces the output where salary column is having NULL.mysql> ... Read More

How can we stuff a string with another one using MySQL functions?

Paul Richard
Updated on 20-Jun-2020 13:05:02

269 Views

MySQL have two functions namely LPAD() and RPAD() with the help of which we can stuff a string with another string.LPAD() function, as the name suggests, left stuff a string with another string. Following is the syntax for using it in MySQL −SyntaxLPAD(original_string, @length, pad_string)Here,  original_string is the string in which we stuff another string.@length is the total length of string returned after stuffing.Pad_string is the string which is to be stuffed with original_string.Examplemysql> SELECT LPAD('tutorialspoint', 18, 'www.'); +----------------------------------+ | LPAD('tutorialspoint', 18, 'www.') | +----------------------------------+ | www.tutorialspoint               | +----------------------------------+ 1 row in set ... Read More

How Can MySQL operator precedence affect result set?

Vikyath Ram
Updated on 20-Jun-2020 13:05:49

139 Views

MySQL follows operator precedence and it has the following list of operators, having the same precedence which is on the same line −INTERVAL BINARY, COLLATE ! - (unary minus), ~ (unary bit inversion) ^ *, /, DIV, %, MOD -, + & | =, , >=, >,

Advertisements