AmitDiwan has Published 10740 Articles

MySQL query to fetch date records greater than the current date after adding days with INTERVAL?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:14:58

641 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    AddDay int,    PostDate date ); Query OK, 0 rows affected (2.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(AddDay, PostDate) values(20, '2019-08-04'); Query OK, ... Read More

Add a new column to table and fill it with the data of two other columns of the same table in MySQL?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:12:07

973 Views

Let us first create a table −mysql> create table DemoTable (    Price int,    Quantity int ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(45, 3); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable ... Read More

Create a temporary table similar to a regular table with MySQL LIKE

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:09:41

209 Views

Let us first create a table −mysql> create table DemoTable1 (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(Name) values('Chris'); Query OK, 1 row affected (0.10 sec) ... Read More

Display record with today and tomorrow’s date from a column with date record in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:07:19

597 Views

Let us first create a table −mysql> create table DemoTable (    AdmissionDate date ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-08-24'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-08-25'); Query OK, 1 ... Read More

How do I sort numbers saved as VARCHAR in MySQL with some of them having preceding 0 like 085, 090, etc.?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:05:29

66 Views

Following is the syntax −select *from yourTableName order by yourColumnName*1, yourColumnName;Let us first create a table −mysql> create table DemoTable (    Value varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('90'); Query OK, 1 row affected ... Read More

Converting boolean values to positive or negative sign in MySQL?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:03:55

387 Views

Following is the syntax −select if(yourColumnName, 1, -1) from yourTableName;Let us first create a table −mysql> create table DemoTable (    isMarried boolean ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(true); Query OK, 1 row affected (0.21 ... Read More

Set a custom value for NULL or empty values in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:00:43

811 Views

Let us first create a table −mysql> create table DemoTable (    Value varchar(100) ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('100'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(''); Query OK, 1 ... Read More

Find the number of logins between two dates in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:59:03

214 Views

Use BETWEEN to find the logins between two dates. Let us first create a table −mysql> create table DemoTable (    Login datetime ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-08-10'); Query OK, 1 row affected (0.11 ... Read More

Display multiple selected rows using MySQL IN()

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:57:35

588 Views

Let us first create a table −mysql> create table DemoTable1045 (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(100) )AUTO_INCREMENT=100; Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1045(FirstName) values('John'); Query OK, 1 row affected (0.15 sec) ... Read More

Advanced sorting in MySQL to display strings beginning with J at the end even after ORDER BY

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:55:12

156 Views

For this, use ORDER BY LIKE operator. Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.17 sec) mysql> ... Read More

Advertisements