AmitDiwan has Published 11365 Articles

Get the SUM of records between two given dates in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 07:01:39

2K+ Views

For this, use BETWEEN keyword. Let us first create a −mysql> create table DemoTable1444    -> (    -> Value int,    -> PurchaseDate datetime    -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert −mysql> insert into DemoTable1444 values(40, '2019-01-10'); Query OK, ... Read More

Effective way to add integers based on table values in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 07:00:07

46 Views

You need to use GROUP BY clause. Let us first create a −mysql> create table DemoTable1443    -> (    -> StudentId int,    -> StudentScore int    -> ); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert −mysql> insert into DemoTable1443 values(100, 78); ... Read More

How to sum rows of VARCHAR datatype or TIME datatype in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:58:28

197 Views

Let us first create a −mysql> create table DemoTable1442    -> (    -> DueTime time    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert −mysql> insert into DemoTable1442 values('00:08:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1442 values('00:04:00'); ... Read More

What is the purpose of ORDER BY columnname*1 in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:57:12

51 Views

MySQL will implicitly convert the column into a number. Following is the syntax −select * from yourTableName  order by yourColumnName*1;Let us first create a −mysql> create table DemoTable1441    -> (    -> Id varchar(30)    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table ... Read More

How to set default value to NULL in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:56:10

4K+ Views

Use DEFAULT keyword in MySQL to set default value to NULL. Let us first create a −mysql> create table DemoTable1440    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20) DEFAULT NULL,    -> StudentAge int DEFAULT NULL    -> ); Query OK, 0 ... Read More

How to check if a specific country code exists in a cell with MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:54:37

184 Views

For specific value, use FIND_IN_SET(). Let us first create a −mysql> create table DemoTable1439    -> (    -> CountryId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CountryCode varchar(20)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert −mysql> insert into ... Read More

How to save JSON array to MySQL database?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:52:58

2K+ Views

For this, you can use JSON data type from MySQL. Let us first create a −mysql> create table DemoTable1438    -> (    -> EmployeeDetails json    -> ); Query OK, 0 rows affected (5.97 sec)Insert some records in the table using insert −mysql> insert into DemoTable1438 values('[{"EmployeeId":"EMP-101", "EmployeeName":"Chris"}, {"EmployeeId":"EMP-102", ... Read More

Create index of three columns in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:50:10

134 Views

For index, you can use KEY(). Let us first create a −mysql> create table DemoTable1437    -> (    -> StudentId int,    -> StudentName varchar(20),    -> StudentMarks int,    -> StudentAge int    -> ,    -> KEY(StudentId, StudentMarks, StudentAge)    -> ); Query OK, 0 rows affected ... Read More

MySQL query to update different fields based on a condition?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:46:44

192 Views

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

MySQL procedure to call multiple procedures?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:44:34

902 Views

Let us first see the syntax, wherein we are calling multiple procedures from a stored procedure −DELIMITER // CREATE PROCEDURE yourProcedureName() BEGIN    CALL yourStoredProcedureName1();    CALL yourStoredProcedureName2();    .    .    N END // DELIMITER //Let us implement the above syntax to call multiple stored procedures.Following is the ... Read More

Advertisements