Found 4378 Articles for MySQL

MySQL query to remove Null Records in a column?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

To remove NULL records in a column, you can use delete command. Following is the syntax −delete from yourTableName where yourColumnName IS NULL;Let us first create a table −mysql> create table removeNullRecordsDemo    -> (    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.50 sec)Following is the query to insert records in the table using insert command −mysql> insert into removeNullRecordsDemo values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into removeNullRecordsDemo values(null); Query OK, 1 row affected (0.15 sec) mysql> insert into removeNullRecordsDemo values('Larry'); Query OK, 1 row affected (0.19 sec) ... Read More

Padding the beginning of a MySQL INT field with zeroes?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

274 Views

You can use LPAD() from MySQL to pad the beginning of a MySQL INT field with zeroes. Let us first create a table.mysql> create table paddingDemo    -> (    -> Number int    -> ); Query OK, 0 rows affected (0.49 sec)Following is the query to insert some records in the table using insert command −mysql> insert into paddingDemo values(78); Query OK, 1 row affected (0.14 sec) mysql> insert into paddingDemo values(560); Query OK, 1 row affected (0.17 sec) mysql> insert into paddingDemo values(888995); Query OK, 1 row affected (0.13 sec) mysql> insert into paddingDemo values(999994); ... Read More

How to remove partial text from value in MySQL?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

466 Views

In order to remove partial text from value, you can use REPLACE() from MySQL. Following is the syntax −update yourTableName set yourColumnName = replace(yourColumnName ,'yourValue ', '' );Let us first create a table −mysql> create table removePartialTextDemo    -> (    -> JavaVersionDetails varchar(100)    -> ); Query OK, 0 rows affected (0.51 sec)Following is the query to insert some records in the table using insert command −mysql> insert into removePartialTextDemo values('Java Version 1.0'); Query OK, 1 row affected (0.50 sec) mysql> insert into removePartialTextDemo values('Java Version 1.1'); Query OK, 1 row affected (0.23 sec) mysql> insert into ... Read More

How to sum the score of students with the same name in MySQL with ORDER BY?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

622 Views

For this, use ORDER BY along with GROUP BY clause. Let us first create a table with Student Name and Score −mysql> create table countRowValueDemo    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20),    -> StudentMathScore int    -> ); Query OK, 0 rows affected (0.71 sec)Following is the query to insert records in the table using insert command −mysql> insert into countRowValueDemo(StudentName, StudentMathScore) values('Larry', 45); Query OK, 1 row affected (0.19 sec) mysql> insert into countRowValueDemo(StudentName, StudentMathScore) values('Mike', 56); Query OK, 1 row affected (0.16 sec) mysql> insert into ... Read More

Convert Date not in a proper format with MySQL?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

94 Views

Assume that the date is in varchar data type i.e. not in the date format.Let us first create a table. Following is the query −mysql> create table convertDateDemo    -> (    -> AdmissionDate varchar(200)    -> ); Query OK, 0 rows affected (0.63 sec)Following is the query to insert some records in the table using insert command −mysql> insert into convertDateDemo values('April 04 2019'); Query OK, 1 row affected (0.18 sec) mysql> insert into convertDateDemo values('May 05 2018'); Query OK, 1 row affected (0.16 sec) mysql> insert into convertDateDemo values('January 01 2012'); Query OK, 1 row affected ... Read More

MySQL query to display databases sorted by creation date?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

438 Views

You can display databases sorted by creation date with ORDER BY clause. Following is the query to display all databases −mysql> show databases;This will produce the following output −+---------------------------+ | Database                  | +---------------------------+ | bothinnodbandmyisam       | | business                  | | commandline               | | customer_tracker_database | | customertracker           | | database1                 | | databasesample            | | demo ... Read More

MySQL query to order rows with value greater than zero?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

454 Views

Let us first create a table. Following is the query −mysql> create table gettingAndOrderingRowsDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Value int    -> ); Query OK, 0 rows affected (1.35 sec)Following is the query to insert some records in the table using insert command −mysql> insert into gettingAndOrderingRowsDemo(Value) values(10); Query OK, 1 row affected (0.33 sec) mysql> insert into gettingAndOrderingRowsDemo(Value) values(13); Query OK, 1 row affected (0.32 sec) mysql> insert into gettingAndOrderingRowsDemo(Value) values(0); Query OK, 1 row affected (0.17 sec) mysql> insert into gettingAndOrderingRowsDemo(Value) values(20); Query OK, 1 ... Read More

Check that a table exists in MySQL?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

698 Views

In order to check a table exists in MySQL, you can use INFORMATION_SCHEMA.TABLES. Let us first create a table −mysql> create table Client_information    -> (    -> Id int,    -> Name varchar(10)    -> ); Query OK, 0 rows affected (0.48 sec)Following is the query to insert some records in the table using insert command −mysql> insert into Client_information values(1, 'Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into Client_information values(2, 'Mike'); Query OK, 1 row affected (0.17 sec) mysql> insert into Client_information values(3, 'Sam'); Query OK, 1 row affected (0.19 sec)Following is the ... Read More

How to write MySQL procedure to insert data into a table?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

547 Views

To write stored procedure to insert data into a table, at first you need to create a table −mysql> create table insertDataUsingStoredProcedure    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY ,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (0.51 sec)Following is the query to write stored procedure to insert data into the table −mysql> DELIMITER // mysql> CREATE PROCEDURE StoredProcedureInsertData(IN StudentName varchar(100), IN StudentAge int)    -> BEGIN    -> insert into insertDataUsingStoredProcedure(Name, Age) values (StudentName, StudentAge );    -> END    -> // Query OK, 0 ... Read More

MySQL query to get the max value with numeric values in varchar field?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

383 Views

To get the max value, use the max() function. Let us create a table first −mysql> create table findMaxValueInVarcharField    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Value varchar(200)    -> ); Query OK, 0 rows affected (1.09 sec)Following is the query to insert some records in the table using insert command −mysql> insert into findMaxValueInVarcharField(Value) values('200'); Query OK, 1 row affected (0.14 sec) mysql> insert into findMaxValueInVarcharField(Value) values('1000'); Query OK, 1 row affected (0.25 sec) mysql> insert into findMaxValueInVarcharField(Value) values('899474'); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More

Advertisements