
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL LIKE Command with Strings Containing Dots
To work with strings containing dots, and display records beginning with a specific number, you need to use REGEXP. Let us first create a table −
mysql> create table DemoTable -> ( -> GameReleaseVersion varchar(20) -> ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('19.6'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('18.4'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('17.6'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('19.5'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------------+ | GameReleaseVersion | +--------------------+ | 19.6 | | 18.4 | | 17.6 | | 19.5 | +--------------------+ 4 rows in set (0.00 sec)
Here is the query that works with a string containing dots. We are fetching records beginning with 19 with some other conditions after dot −
mysql> select *from DemoTable -> where GameReleaseVersion regexp '^19\.[0-9]+$';
This will produce the following output −
+--------------------+ | GameReleaseVersion | +--------------------+ | 19.6 | | 19.5 | +--------------------+ 2 rows in set (0.15 sec)
Advertisements