Found 4219 Articles for MySQLi

How can I customize value, instead of NULL, of a row by using MySQL IF() function?

Arushi
Updated on 11-Feb-2020 06:18:34

52 Views

Suppose in our ‘Employee’ table we are having NULL as the value of ‘salary’ column for two employees. The data, shown as follows, is itself not meaningful.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   | NULL   | | 8 ... Read More

How can I use a SELECT statement as an argument of MySQL IF() function?

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

389 Views

It is quite possible to use a SELECT statement as the first argument of MySQL IF() function. To make it understand, consider the data as follows from table ‘Students’. mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name | Country | Language | Course | +----+-----------+-----------+----------+----------------+ | 1 | Francis | UK | English | Literature | | 2 | Rick | ... Read More

How can I use MySQL IF() function within SELECT statement?

Monica Mona
Updated on 10-Feb-2020 10:40:37

3K+ Views

It is quite possible to use MySQL IF() function within SELECT statement by providing the name of the column along with a condition as the first argument of IF() function. To understand it, consider the following data from table ‘Students’.mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name      | Country   | Language | Course         | +----+-----------+-----------+----------+----------------+ | 1  | Francis   | UK        | English  | Literature     | | 2  | Rick      | USA       | English  | History        | ... Read More

How does MySQL IF() function work?

Ankith Reddy
Updated on 20-Jun-2020 13:22:56

104 Views

MySQL IF() function is one of the MySQL control flow functions that returns a value based on a condition. It is sometimes referred to as IF ELSE or IF THEN ELSE function. Basically, it takes three expressions and if the first expression is true (not ZERO and not NULL), it returns the second expression. Otherwise, it returns the third expression. Its syntax is as follows −SyntaxIF(expr, value_if_true, value_if_false)Here expr is the expression having some condition.Value_if_true is the value to return if expr evaluates to TRUE.Value_if_false is the value to return if expr evaluates to FALSE.Examplemysql> Select IF(100=100, 'YES', 'NO'); +------------------------+ | ... Read More

In MySQL, without having BOOLEAN data type how can we show TRUE and FALSE values?

Sharon Christine
Updated on 20-Jun-2020 13:23:30

148 Views

As we know that there is no BOOLEAN data type in MySQL hence by using TRUE or true, FALSE or false we can enter Boolean values in MySQL statement.Examplemysql> Select TRUE,FALSE; +------+-------+ | TRUE | FALSE | +------+-------+ |    1 |     0 | +------+-------+ 1 row in set (0.00 sec) mysql> Select true,false; +------+-------+ | TRUE | FALSE | +------+-------+ |    1 |     0 | +------+-------+ 1 row in set (0.00 sec)

How can we combine functions in MySQL?

Chandu yadav
Updated on 10-Feb-2020 10:43:23

436 Views

Combining of functions in MySQL is quite possible by providing a function as the argument of other function. It is also called nesting of functions. To understand it, consider some examples belowmysql> Select UPPER(CONCAT('www.', 'tutorialspoint', '.com'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | WWW.TUTORIALSPOINT.COM | +------------------------+ 1 row in set (0.00 sec) mysql> Select LOWER(CONCAT('WWW.', 'TUTORIALSPOINT', '.COM'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | www.tutorialspoint.com | +------------------------+ 1 row in set (0.00 sec)The above queries combine UPPER() and LOWER() function with CONCAT() function.Similarly, we can combine more ... Read More

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

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

82 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

226 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

241 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

959 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

Advertisements