AmitDiwan has Published 10740 Articles

How to check the column values have string or digits in MySQL?

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:22:19

1K+ Views

If you want only the string values, then use the below syntax −select *from yourTableName where yourColumnName NOT regexp '^[0-9]+$';If you want only the digit, then use the below syntax −select *from yourTableName where yourColumnName regexp '^[0-9]+$';Let us first create a table −mysql> create table DemoTable(    Id varchar(100) ); ... Read More

Insert multiple values in a temporary table with a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:19:24

816 Views

Let us first create a table −mysql> create temporary table DemoTable (    SerialNumber int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command. Here, we are inserting multiple values in a temporary table −mysql> insert into DemoTable values(1), (2), (3), (4), (5), ... Read More

Check if the column values are the same among multiple records and set these records in a single row separated by a special character in MySQL

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:17:25

94 Views

For this, you can use GROUP_CONCAT() along with DISTINCT. Let us first create a table −mysql> create table DemoTable (    Id int,    Subject varchar(40) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'MySQL'); Query OK, ... Read More

MySQL query to display only the records that contains single word?

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:15:37

334 Views

For this, you can filter records on the basis of LIKE. Let us first create a table −mysql> create table DemoTable (    Name varchar(50) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John Smith'); Query OK, 1 ... Read More

MySQL query to sort increasing the difference between n and the value in the table?

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:14:12

84 Views

For sort by distance, use ORDER BY ABS(). Let us first create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (1.16 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.51 sec) ... Read More

Fetch date record that equals today in MySQL

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:12:11

162 Views

For this, compare the date records with the current date using the CURDATE() method. Let us first create a table −mysql> create table DemoTable (    RegistrationLastDate datetime ); Query OK, 0 rows affected (0.61 sec)Let’s say the current date is −2019-09-03Insert some records in the table using insert command ... Read More

MySQL ORDER BY CASE to display special character in the beginning

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:10:00

631 Views

Let us first create a table −mysql> create table DemoTable (    StudentId varchar(40) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20); Query OK, 1 ... Read More

How to create NVARCHAR column in MySQL?

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:07:20

3K+ Views

The MySQL converts NVARCHAR() to VARCHAR(). NVARCHAR stands for National Varchar in MySQL. Let us first create a table with one of the columns “StudentName” as NVARCHAR −mysql> create table DemoTable (    StudentName NVARCHAR(40),    StudentCountryName VARCHAR(50) ); Query OK, 0 rows affected, 1 warning (0.49 sec)Let us check ... Read More

MySQL query to update all the values in a column with numeric incremental values like John1, John2, John3, etc.

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:03:57

278 Views

To update all the values in a column to John1, John2, etc.; you need to set incremental values 1, 2, 3, etc. and concatenate them to the records. Let us first create a table −mysql> create table DemoTable (    StudentId varchar(80) ); Query OK, 0 rows affected (0.50 sec)Insert ... Read More

How to delete records based on a word with underscore like MONTH_JAN'?

AmitDiwan

AmitDiwan

Updated on 04-Oct-2019 07:01:23

185 Views

For this, you can use LIKE operator. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(40),    BornMonth varchar(40) ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Advertisements