AmitDiwan has Published 10744 Articles

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

AmitDiwan

AmitDiwan

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

90 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

271 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

80 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

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

294 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

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

214 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

278 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

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

Order dates in MySQL with the format “01 August 2019”?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:42:24

102 Views

To display dates like “01 August 2019”, use ORDER BY STR_TO_DATE(). Let us first create a −mysql> create table DemoTable1435    -> (    -> DueDate varchar(60)    -> ); Query OK, 0 rows affected (1.08 sec)Insert some records in the table using insert −mysql> insert into DemoTable1435 values('01 August ... Read More

Advertisements