Found 4219 Articles for MySQLi

Select rows having more than 2 decimal places in MySQL?

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

936 Views

To select rows with more than 2 decimal places, use SUBSTR() function from MySQL. Let us first create a table −mysql> create table selectRows2DecimalPlacesDemo    -> (    -> Amount varchar(100)    -> ); Query OK, 0 rows affected (0.73 sec)Following is the query to insert records in the table using insert command −mysql> insert into selectRows2DecimalPlacesDemo values('234.5678'); Query OK, 1 row affected (0.17 sec) mysql> insert into selectRows2DecimalPlacesDemo values('19.50'); Query OK, 1 row affected (0.19 sec) mysql> insert into selectRows2DecimalPlacesDemo values('23.456'); Query OK, 1 row affected (0.17 sec) mysql> insert into selectRows2DecimalPlacesDemo values('12.123'); Query OK, 1 row affected (0.14 ... Read More

Replace part of string in MySQL table column?

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

380 Views

To replace part of string in MySQL table column, you can use REPLACE(). Following is the syntax −update yourTableName set yourColumnName = REPLACE(yourColumnName ,'yourOldValue', 'yourNewValue');Let us first create a table −mysql> create table replacePartOfStringDemo    -> (    -> WebsiteURL varchar(100)    -> ); Query OK, 0 rows affected (0.47 sec)Following is the query to insert records in the table using insert command −mysql> insert into replacePartOfStringDemo(WebsiteURL) values('www.mysqlQuestion.com'); Query OK, 1 row affected (0.14 sec)Following is the query to display all records from the table using select statement −mysql> select * from replacePartOfStringDemo;This will produce the following output −+-----------------------+ | ... Read More

How to strip all spaces from a column in MySQL?

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

1K+ Views

To strip all spaces from a column in MySQL, you can use REPLACE() function. Following is the syntax −update yourTableName set yourColumnName=REPLACE(yourColumnName, ' ', '' );Let us first create a table −mysql> create table stripAllSpacesDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.56 sec)Following is the query to insert records in the table using insert command −mysql> insert into stripAllSpacesDemo(Name) values('Jo h n'); Query OK, 1 row affected (0.19 sec) mysql> insert into stripAllSpacesDemo(Name) values(' Joh n'); Query OK, 1 row affected (0.16 ... Read More

How do I insert a NULL value in MySQL?

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

3K+ Views

To insert a NULL value, you can use UPDATE command. Following is the syntax −UPDATE yourTableName SET yourColumnName=NULL;Let us first create a table −mysql> create table insertNullValue    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(100),    -> ClientCountryName varchar(20)    -> ); Query OK, 0 rows affected (0.54 sec)Following is the query to insert some records in the table using insert command −mysql> insert into insertNullValue(ClientName, ClientCountryName) values('Larry', 'US'); Query OK, 1 row affected (0.19 sec) mysql> insert into insertNullValue(ClientName, ClientCountryName) values('David', 'AUS'); Query OK, 1 row affected (0.09 sec) ... Read More

Check privileges (grants) for a specific user in MySQL?

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

472 Views

If you want to check privileges for a specific user, then use the below syntax −SHOW GRANTS FOR 'yourUserName'@'yourHostName';The above syntax will check privileges for a specific user.To check the privileges for a specific user, then use FOR. Let’s say we have a username ‘JOHN‘ and host is ‘%’. Following is the query to get the privileges for user “JOHN” −mysql> SHOW GRANTS FOR 'JOHN'@'%';This will produce the following output −+--------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------- --------------+ | Grants for JOHN@% | +--------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------- --------------+ | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, ... Read More

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

623 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

Advertisements