AmitDiwan has Published 10740 Articles

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

320 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

230 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

307 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

118 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

Insert current time minus 1 hour to already inserted date-time records in MYSQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:40:43

1K+ Views

For subtracting dates, use MySQL DATE_SUB(). Let us first create a −mysql> create table DemoTable1434    -> (    -> ArrivalDatetime datetime    -> ); Query OK, 0 rows affected (3.14 sec)Insert some records in the table using insert −mysql> insert into DemoTable1434 values('2019-09-30 21:10:00'); Query OK, 1 row affected ... Read More

Store strings in variables and concatenate them to display them in a single column in MYSQL

AmitDiwan

AmitDiwan

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

308 Views

For this, use CONCAT_WS() in MySQL. Let us first create a −mysql> create table DemoTable1433    -> (    -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientFirstName varchar(20),    -> ClientLastName varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table ... Read More

Fetch specific rows from a MySQL table with duplicate column values (names)?

AmitDiwan

AmitDiwan

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

163 Views

Let us first create a −mysql> create table DemoTable1431    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeCountryName varchar(20)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert −mysql> insert into DemoTable1431(EmployeeName, ... Read More

Advertisements