AmitDiwan has Published 10740 Articles

Search for specific characters within a string with MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 12:10:10

433 Views

For this, use REGEXP. For example, characters J, A, V and A. Let us first create a table −mysql> create table DemoTable (    Value varchar(50) ); Query OK, 0 rows affected (3.92 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('XYSJGHAKLMVDFFSA'); Query OK, 1 ... Read More

Count values greater and less than a specific number and display count in separate MySQL columns?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 12:07:56

1K+ Views

For this, you can use COUNT() along with CASE STATEMENT. Let us first create a table −mysql> create table DemoTable (    Score int ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(40); Query OK, 1 row affected ... Read More

How to select a specific record from MySQL if date is in VARCHAR format?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 12:06:06

264 Views

For this, use STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable (    DueDate varchar(60) ) ; Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('12-AUG-2016'); Query OK, 1 row affected (0.11 sec) mysql> insert into ... Read More

Use MySQL to find duplicates and display in a single line

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 12:04:05

297 Views

For this, you can use GROUP_CONCAT() along with GROUP BY clause. Both are used to group concat duplicates and display in a single line. Let us first create a table −mysql> create table DemoTable (    StudentFavouriteSubject varchar(40),    StudentName varchar(40) ) ; Query OK, 0 rows affected (0.75 sec)Insert ... Read More

Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:59:14

306 Views

Yes, you can search for particular numbers using the MySQL FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable (    ListOfNumbers varchar(100) ); Query OK, 0 rows affected (1.24 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('784, 746, 894, 344'); Query ... Read More

MySQL query to group concat and place data into a single row on the basis of 1 values in corresponding column?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:56:00

141 Views

For this, use GROUP_CONCAT(). For only 1 values, work with MySQL WHERE clause. Let us first create a table −mysql> create table DemoTable (    PlayerName varchar(40),    PlayerStatus tinyint(1) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

How to remove -XXX from Zip Code field using MySQL REGEXP?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:52:27

241 Views

The easiest way to achieve this is by using the MySQL SUBSTRING_INDEX() function. Let us first create a table −mysql> create table DemoTable (    ZipCode varchar(50) ); Query OK, 0 rows affected (2.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('52533-909'); Query OK, ... Read More

MySQL SELECT from two tables with a single query

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:49:47

3K+ Views

Use UNION to select from two tables. Let us first create a table −mysql> create table DemoTable1 (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20) ); Query OK, 0 rows affected (0.90 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(FirstName) values('Chris') ... Read More

Get row data for the lowest and highest values in a MySQL column

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:45:53

555 Views

For the lowest values in a MySQL column, use the MIN() method and for highest, use the MAX() method. Let us first create a table −mysql> create table DemoTable (    CustomerName varchar(20),    ProductAmount int ) ; Query OK, 0 rows affected (1.03 sec)Insert some records in the table ... Read More

How can I avoid too many OR statements in a MySQL query?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:40:36

261 Views

Use MySQL IN() to avoid too many OR statements. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(40) ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Advertisements