AmitDiwan has Published 10740 Articles

Fetch datetime row from exactly past 7 days records in MySQL

AmitDiwan

AmitDiwan

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

786 Views

For this, you can use the INTERVAL 7 day concept. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    AdmissionDate datetime ); Query OK, 0 rows affected (0.83 sec)Note − Let’s say the current date is 2019-08-23.Insert some records ... Read More

Fetching records from a table with NULL and other values on the basis of conditions in MySQL

AmitDiwan

AmitDiwan

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

137 Views

Let us first create a table −mysql> create table DemoTable (    value1 int,    value2 int,    value3 int ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20, 40, null); Query OK, 1 row affected (0.23 sec) ... Read More

MySQL query to ORDER BY records on the basis of modulus result

AmitDiwan

AmitDiwan

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

180 Views

For this, use ORDER BY with a modulus operator. Let us first create a table −mysql> create table DemoTable (    StudentId int,    StudentName varchar(100) ); Query OK, 0 rows affected (1.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, ... Read More

MySQL multiple COUNT with multiple columns?

AmitDiwan

AmitDiwan

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

425 Views

You can use an aggregate function SUM() along with IF(). Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (2.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'Smith'); Query ... Read More

Use LIKE % to fetch multiple values in a single MySQL query

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 07:00:04

4K+ Views

To fetch multiple values wit LIKE, use the LIKE operator along with OR operator. Let us first create a table −mysql> create table DemoTable1027 (    Id int,    Name varchar(100) ); Query OK, 0 rows affected (1.64 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

MySQL select query to fetch data with null value?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 06:57:06

545 Views

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

Show column value twice in MySQL Select?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 06:54:42

302 Views

You can use concat(). Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable ... Read More

Get count of zeros for columns values declared with INT type in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 06:52:26

276 Views

For this, you can use LENGTH() along with REPLACE(). Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10002000); Query OK, 1 row affected (0.09 ... Read More

Return value from a row if it is NOT NULL, else return the other row value in another column with MySQL

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 06:50:15

285 Views

For this, you can use IFNULL(). Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected ... Read More

MySQL query to compare and display only the rows with NULL values

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 06:48:14

180 Views

For this, you can use IFNULL(). Let us first create a table −mysql> create table DemoTable (    Value1 int,    Value2 int ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, NULL); Query OK, 1 row affected ... Read More

Advertisements