George John has Published 1081 Articles

How do I show a MySQL warning that just happened?

George John

George John

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

344 Views

To show a MySQL warning, you can use the below syntax −SHOW WARNINGS;The above syntax only displays the immediate warning from MySQL prompt. Suppose you run another query between them or you have lost the MySQL connection, then SHOW WARNINGS will not work.Here is the query to display warnings −mysql> ... Read More

MySQL SELECT IF statement with OR?

George John

George John

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

1K+ Views

You can use SELECT IF statement with OR. To understand select with OR, let us create a table. The query to create a table is as follows −mysql> create table EmployeeInformation    -> (    -> EmployeeId int,    -> EmployeeName varchar(100),    -> EmployeeStatus varchar(100)    -> ); Query ... Read More

How to part DATE and TIME from DATETIME in MySQL?

George John

George John

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

596 Views

To part DATE and TIME from DATETIME, you can use the DATE_FORMAT() method from MySQL. The syntax is as follows −SELECT DATE_FORMAT(yourColumnName, '%Y-%m-%d') VariableName, DATE_FORMAT(yourColumnName, '%H:%i:%s') VariableName from yourTableName;To understand the above method DATE_FORMAT(), let us create a table with data type “datetime”.Creating a table −mysql> create table DateAndTimePartDemo ... Read More

How to check for duplicates in MySQL table over multiple columns?

George John

George John

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

2K+ Views

To check for duplicates in MySQL, you can use group by having clause. The syntax is as follows.select yourColumnName1, yourColumnName2, ......N, count(*) as anyVariableName from yourTableName group by yourColumnName1, yourColumnName2 having count(*) > 1;To understand the above syntax, let us create a table. The query to create a table is ... Read More

MySQL UPDATE the corresponding column with random number between 1-3?

George John

George John

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

1K+ Views

For random numbers in a range, you need to use the RAND() method from MySQL. The syntax is as follows for update −UPDATE yourTableName set yourColumnName=value where yourColumnName2=(SELECT FLOOR(1+RAND()*3));In the above query, the statement FLOOR(1+RAND()*3) generates the number between 1-3 and update the column.To understand the above syntax, let us ... Read More

How to check if android application is running background?

George John

George John

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

3K+ Views

There are so many situations, that we should find android application is running background or not. This example demonstrates how to check if an android application is running background.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

Storing money amounts in MySQL?

George John

George John

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

8K+ Views

To store money amounts in MySQL, the best choice is to use DECIMAL data type or NUMERIC type. Float data type is not a good choice for money amounts. It gives some rounding errors. Therefore, avoid float for money amounts.Let us first create a table with data type DECIMAL. The ... Read More

Calculate age based on date of birth in MySQL?

George John

George John

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

12K+ Views

Calculate Age based on date of birth with the help of DATE_FORMAT() method in MySQL. Firstly, get the current date time with the help of now() method and you can place your date of birth in DATE_FORMAT().The syntax is as follows −SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(now(), 'yourDateofbirth')), '%Y')+0 AS anyVariableName;Apply the above syntax ... Read More

MySQL Server port number?

George John

George John

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

828 Views

If you will install MySQL on your system, then you will get the default MySQL server port number i.e. 3306.To know the MySQL server port number, you can use the following query. Here, we have used the SHOW VARIABLES command. The query is as follows −mysql> SHOW VARIABLES WHERE Variable_Name ... Read More

Convert DateTime Value into String in MySQL?

George John

George John

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

3K+ Views

To convert the DateTime value into string in MySQL, you can use the DATE_FORMAT() function. The syntax is as follows −select date_format(yourColumnName, ‘%d %m %y’) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table ... Read More

Advertisements