George John has Published 1081 Articles

Conditional NOT NULL case MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:24

802 Views

For conditional NOT NULL case, you do not need to use and = operator. You need to use IS NULL and IS NOT NULL property because NULL is a special case in MySQL.To understand the conditional NOT NULL case, let us create a table. The query to create a ... Read More

Sort by order of values in a MySQL select statement IN clause?

George John

George John

Updated on 30-Jul-2019 22:30:24

168 Views

You can use field() function with ORDER BY clause to sort by order of values. The syntax is as followsSELECT *FROM yourTableName WHERE yourColumnName IN(Value1, Value2, Value3, .......N); ORDER BY FIELD(yourColumnName ,Value1, Value2, Value3, .......N);To understand the above syntax, let us create a table. The query to create a table ... Read More

MySQL stored procedure return value?

George John

George John

Updated on 30-Jul-2019 22:30:24

14K+ Views

To return a value from stored procedure, you need to use user defined session specific variable. Add @ symbol before variable name.For example, use @symbol for variable valido. The syntax for the same is as follows:SELECT @valido;Whenever you use select statement, you need to use @anyVariableName. The syntax is as ... Read More

When the MySQL delimiter error occur?

George John

George John

Updated on 30-Jul-2019 22:30:24

2K+ Views

The MySQL delimiter occurs when you are using a pipe delimiter(|) with semicolon (;) and using MySQL version lower than 8.0.12.MySQL treats the pipe (|) as one delimiter and semicolon (;) is another delimiter. Therefore, do not confuse the MySQL delimiter with pipe as well as semicolon.Note: Here, we are ... Read More

How to insert DECIMAL into MySQL database?

George John

George John

Updated on 30-Jul-2019 22:30:24

8K+ Views

To insert decimal into MySQL, you can use DECIMAL() function from MySQL. The syntax is as followsyourColumnName DECIMAL(TotalDigit, DigitAfterDecimalPoint);To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table DecimalInsert    -> (    -> Id int,    -> Name ... Read More

How to output MySQL query results in CSV format and display it on the screen, not a file?

George John

George John

Updated on 30-Jul-2019 22:30:24

659 Views

To get the output MySQL query result in CSV format, use concat(). The syntax is as follows −mysql> select concat(StudentId, ', ', StudentName, ', ', StudentAge) as CSVFormat from CSVFormatOutputs;To understand the above syntax, let us create a table. The query to create a table is as follows−mysql> create table ... Read More

How to implement WHILE LOOP with IF STATEMENT MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:24

546 Views

The following is an example to implement MySQL WHILE LOOP with IF statement. We are using in a stored procedureThe following is the query to create our stored procedure:mysql> DELIMITER // mysql> create procedure sp_getDaysDemo() -> BEGIN -> SELECT MONTH(CURDATE()) INTO @current_month; ... Read More

How can a query multiply 2 cells for each row in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:24

204 Views

You can use multiplication operator (*) between two cells. The syntax is as followsSELECT yourColumnName1, yourColumnName2, yourColumnName1*yourColumnName2 as ‘anyVariableName’ from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table MultiplicationDemo    -> (    -> FirstPrice int,   ... Read More

MySQL convert timediff output to day, hour, minute, second format?

George John

George John

Updated on 30-Jul-2019 22:30:24

1K+ Views

To understand the MySQL convert timediff output to day, hour, minute, and second format, you need to use CONCAT() from MySQL.Let us create a table. The query to create a table is as follows:mysql> create table convertTimeDifferenceDemo -> ( -> Id int NOT NULL ... Read More

MySQL concat_ws() method usage

George John

George John

Updated on 30-Jul-2019 22:30:24

143 Views

To get the output MySQL query result in CSV format, use concat_ws(). The syntax is as follows −SELECT CONCAT_WS(‘, ’, yourColumnName1, yourColumnName2, yourColumnName3, ....N) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CSVFormatOutputs ... Read More

Advertisements