AmitDiwan has Published 9818 Articles

MySQL left padding with zeros separated by hyphen?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:28:57

190 Views

Let us first create a table −mysql> create table DemoTable829(SerialNumber int); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable829 values(100); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable829 values(101); Query OK, 1 row affected (0.26 sec) ... Read More

Display substrings of different length with a single MySQL query and combine the result

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:26:31

160 Views

Let us first create a table −mysql> create table DemoTable856(Title text); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable856 values('Introduction to MySQL'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable856 values('Java in depth'); Query OK, 1 ... Read More

Remove only the percentage sign from values in a MySQL table?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:24:31

432 Views

Let us first create a table −mysql> create table DemoTable828(    CustomerName varchar(100),    InterestRate varchar(100) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable828 values('Chris', '10%'); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable828 values('Robert', ... Read More

How to check if a timestamp is set in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:22:57

398 Views

Let us first create a table −mysql> create table DemoTable855(DueDate timestamp); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable855 values('2019-08-07'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable855 values('0000-00-00'); Query OK, 1 row affected (0.27 sec) ... Read More

MySQL query to replace only the backslashes from folder path?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:21:28

318 Views

To replace backslashes with any other special character, use the REPLACE() method. Let us first create a table −mysql> create table DemoTable827(Path text); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable827 values('C\MySQL'); Query OK, 1 row affected (0.12 sec) ... Read More

How to do a sum of previous row value with the current row and display the result in another row with MySQL cross join?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:20:14

1K+ Views

Let us first create a table −mysql> create table DemoTable(Value int); Query OK, 0 rows affected (1.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.68 sec) ... Read More

MySQL query to display only the column values with corresponding column having whitespace

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:19:19

271 Views

For this, use the TRIM() function. Let us first create a table −mysql> create table DemoTable826(    FirstName varchar(100),    Age int ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using the insert command. Here, we have set the FirstName as whitespace for some of ... Read More

How to optimize a MySQL table after deleting some rows?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:17:39

1K+ Views

Use the OPTIMIZE TABLE command to optimize a MySQL table −optimize table yourTableName;Let us first create a table −mysql> create table DemoTable(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100) ); Query OK, 0 rows affected (1.38 sec)Insert some records in the table using insert command −mysql> ... Read More

Implement a MySQL Void Query that does nothing

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:12:28

337 Views

Let us first create a table −mysql> create table DemoTable(Name varchar(100)); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.11 sec) ... Read More

Updating last entry of a particular ID in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:11:13

253 Views

To update the last entry of a particular ID in MySQL, use ORDER BY DESC LIMIT 1. This would allow you to update the last entry i.e. row records.Let us first create a table −mysql> create table DemoTable824(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(100),   ... Read More

Advertisements