MySQL Articles

Page 116 of 355

In which conditions, MySQL CASE statement return NULL?

Arjun Thakur
Arjun Thakur
Updated on 11-Feb-2020 1K+ Views

As we know that if no comparison or condition is true then CASE statement returns the result specified after ELSE statement. But what if there is no ELSE statement, then in this situation, CASE statement would return NULL. Following is an example to demonstrate it.Examplemysql> Select CASE 100 -> WHEN 150 THEN 'It is matched' -> WHEN 200 THEN 'It is not matched' -> END As 'It Returns NULL'; +-----------------+ | It Returns NULL | +-----------------+ | NULL ...

Read More

How does MYSQL control flow function CASE works?

Swarali Sree
Swarali Sree
Updated on 11-Feb-2020 451 Views

MySQL CASE statement is a flow control function that allows us to build conditions inside a query such as SELECT or WHERE clause. We have two syntaxes of CASE statementSyntax-1CASE val WHEN compare_val1 THEN result1 WHEN compare_val2 THEN result2 . . . Else result ENDHere in this 1st syntax, if the val is equal to compare_val1 then the CASE statement returns result1. If the val is equal to compare_val2 then the CASE statement returns result2 and so on.In case if the val does not match any compare_val then the CASE statement returns the result specified in ELSE clause.Examplemysql> Select CASE 100 ...

Read More

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

Arushi
Arushi
Updated on 11-Feb-2020 165 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 we combine functions in MySQL?

Chandu yadav
Chandu yadav
Updated on 10-Feb-2020 641 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 I use MySQL IF() function within SELECT statement?

Monica Mona
Monica Mona
Updated on 10-Feb-2020 4K+ 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

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
Priya Pallavi
Updated on 10-Feb-2020 2K+ 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

Mean and Mode in SQL Server

Narendra Kumar
Narendra Kumar
Updated on 10-Feb-2020 2K+ Views

Problem statementMean is the average of the given data set calculated by dividing the total sum by the number of values in the data set.Mode of a data set is the value that appears most frequently in a series of dataIf our dataset is {1, 2, 3, 4} then mean value is − (1 + 2 + 3 + 4) / 4 = 2.5If our dataset is {1, 2, 3, 4, 1, 1, 1, 1} then mode value is − 1 as it appears 5 times.ExampleFirst, create a table −CREATE TABLE NUMBERS (    value INT )Insert data into the ...

Read More

What is the resemblance of COALESCE() function with IF-THEN-ELSE statement?

Arushi
Arushi
Updated on 10-Feb-2020 659 Views

As we know that COALESCE() function returns first non-NULL value from the list of values. The following IF-THEN-ELSE statement is equivalent to COALESCE() function.IF value1 is not NULL THEN output = value1; ELSIF value2 is not NULL THEN output = value2; ELSIF value3 is not NULL THEN output = value3; . . . ELSIF valueN is not NULL THEN output = valueN; ELSE output = NULL; END IF;

Read More

What MySQL COALESCE() function returns if all the arguments provided to it are NULL?

Arjun Thakur
Arjun Thakur
Updated on 10-Feb-2020 1K+ Views

If all the values in MySQL COALESCE() function are NULL then it returns NULL as the output. It means that this function does not find any non-NULL value in the list.Examplemysql> Select COALESCE(NULL, NULL, NULL, NULL); +----------------------------------+ | COALESCE(NULL, NULL, NULL, NULL) | +----------------------------------+ |                             NULL | +----------------------------------+ 1 row in set (0.00 sec)

Read More

How can we split the name string into two parts by using MySQL SUBSTRING_INDEX() function?

Fendadis John
Fendadis John
Updated on 10-Feb-2020 354 Views

To make it understand, we are using the following data from a table named ‘customerdetail’.mysql> Select * from Customerdetail; +----------------------+----------------------+-----------+---------------------+ | Name                 | FName                | Address   | Emailid             | +----------------------+----------------------+-----------+---------------------+ | Advik Jhamb          | Lovkesh Jhamb        | Mumbai    | Advik@gmail.com     | | Chirag Jai Patil     | Raman Jai Patil      | Gujrat    | chirahp@yahoo.com   | | Devansh Singh Rajput | Kishore Singh Rajput ...

Read More
Showing 1151–1160 of 3,547 articles
« Prev 1 114 115 116 117 118 355 Next »
Advertisements