George John has Published 1167 Articles

How to implement WHILE LOOP with IF STATEMENT MySQL?

George John

George John

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

392 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

157 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

99 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

How to set sql_mode permanently in MySQL?

George John

George John

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

795 Views

If you are using Windows Operating System, check your directory my.cnf or my.ini file.mysql> select @@datadir;The following is the output+---------------------------------------------+ | @@datadir ... Read More

How to remove special characters from a database field in MySQL?

George John

George John

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

19K+ Views

You can remove special characters from a database field using REPLACE() function. The special characters are double quotes (“ “), Number sign (#), dollar sign($), percent (%) etc.The syntax is as follows to remove special characters from a database field.UPDATE yourTableName SET yourColumnName=REPLACE(yourColumnName, ’yourSpecialCharacters’, ’’);To understand the above syntax, let ... Read More

Equivalent of SQL Server IDENTITY Column in MySQL?

George John

George John

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

8K+ Views

Equivalent of Microsoft SQL Server IDENTITY column in MySQL is AUTO_INCREMENT. The IDENTITY in SQL Server acts like AUTO_INCREMENT in MySQL.The syntax is as follows −CREATE TABLE yourTableName (    yourColumnName1 dataType NOT NULL AUTO_INCREMENT,    yourColumnName2 dataType,    .    .    .    N,    PRIMARY KEY(yourColumnName1) );In ... Read More

Remove trailing zeros in decimal value with changing length in MySQL?

George John

George John

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

10K+ Views

You can remove trailing zeros using TRIM() function. The syntax is as follows.SELECT TRIM(yourColumnName)+0 FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeTrailingZeroInDecimal    -> (    -> Id int not null auto_increment,    -> ... Read More

How to update data in a MySQL database with Java?

George John

George John

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

3K+ Views

To update data into a MySQL database table, use UPDATE command. The syntax is as follows −update yourTableName set yourColumnName1 = value1, ....N where condition;First, we need to create a table. The query is as follows −mysql> create table UpdateDemo    -> (    -> id int,    -> Name ... Read More

Python interface for SQLite databases

George John

George John

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

260 Views

SQLite is an open source database and is serverless that needs no configuration. Entire database is a single disk file that can be placed anywhere in operating system's file system. SQLite commands are similar to standard SQL. SQLite is extensively used by applications such as browsers for internal data storage. ... Read More

Advertisements