George John has Published 1167 Articles

How to select all records that are 10 minutes within current timestamp in MySQL?

George John

George John

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

2K+ Views

You can select all records that are 10 minutes within current timestamp using the following syntax−SELECT *FROM yourTableName WHERE yourColumnName > = DATE_SUB(NOW(), INTERVAL 10 MINUTE);To understand the above syntax, let us create a table. The query to create a table is as follows−mysql> create table users    -> ( ... Read More

How to replace values of select return in MySQL?

George John

George John

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

916 Views

You can use select case statement for this. The syntax is as follows.select yourColumnName1, yourColumnName2, ...N, case when yourColumnName=1 then 'true' else 'false' end 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 selectReturnDemo -> ... Read More

How to search for exact string in MySQL?

George John

George John

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

1K+ Views

You can use binary to search for exact string in MySQL. The syntax is as follows:SELECT * FROM yourTableName WHERE BINARY yourColumnName = yourStringValue;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table ExactSearch    -> (    -> ... Read More

What is the difference between MySQL TINYINT(2) vs TINYINT(1)?

George John

George John

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

1K+ Views

The number 2 and 1 in TINYINT(2) vs TINYINT(1) indicate the display width. There is no difference between tinyint(1) and tinyint(2) except the width.If you use tinyint(2) or even tinyint(1), the difference is the same. You can understand the above concept using zerofill option.tinyint(1) zerofilltinyint(2) zerofillLet us create a table. ... Read More

How do I show a MySQL warning that just happened?

George John

George John

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

288 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

834 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

473 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

1K+ 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

799 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

2K+ 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

Advertisements