AmitDiwan has Published 10744 Articles

How to select all the characters after the first 20 characters from a column in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:11:59

253 Views

Let us first create a table −mysql> create table DemoTable (    Title text ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('C is a good programming language to start'); Query OK, 1 row affected (0.18 sec) mysql> ... Read More

MySQL query to find single value from duplicates with certain condition by excluding other records using NOT IN

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:08:35

89 Views

Let us first create a table −mysql> create table DemoTable (    Id int,    FirstName varchar(100) ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable ... Read More

Underscore as a table name in MySQL is possible?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:05:44

250 Views

Yes, we can add underscore as a table name using backticks around the table name. Following is the syntax −INSERT INTO `yourTableName` values(yourValue1, .......N);Let us first create a table −mysql> create table `DemoTable_1` (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Location varchar(100) ); Query OK, 0 rows ... Read More

Delete records from a MySQL table by excluding non-deleted records using NOT IN

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:03:44

184 Views

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

Return only the first 15 characters from a column with string values in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:01:47

766 Views

To return only the first 15 characters from string values, use the MySQL SUBSTR() function.Let us first create a table −mysql> create table DemoTable (    Title varchar(100) ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Introduction to ... Read More

Add a percentage (%) sign at the end to each value while using MySQL SELECT statement

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 06:59:14

4K+ Views

To add percentage sign at the end, use CONCAT() function. Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100),    StudentScore int ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert ... Read More

Add leading zeros to a MySQL column?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 06:54:44

1K+ Views

To add leading zeros, you can use LPAD(). Let us first create a table −mysql> create table DemoTable (    Code varchar(100) ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('JS'); Query OK, 1 row affected (0.15 sec) ... Read More

How to convert yyyymmdd in INT type to date?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 06:51:43

299 Views

For this, you can use the DATE() function. Let us first create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20190108); Query OK, 1 row affected (0.11 sec) ... Read More

Find the average of column values in MySQL using aggregate function

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 06:48:43

119 Views

Let us first create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(78); Query OK, 1 ... Read More

MySQL query to delete table rows if string in cell is matched

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 12:27:43

271 Views

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 (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John Smith'); Query OK, 1 row affected (0.17 ... Read More

Advertisements