- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Searching for an integer value in a varchar field in MySQL?
To search for an integer value in a varchar filed, you can use CASE statement.
Let us first create a table. Consider, we have a list of email-ids −
mysql> create table DemoTable -> ( -> Title varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('9John@example.com'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('3Carol@gmail.com'); Query OK, 1 row affected (0.45 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-------------------+ | Title | +-------------------+ | 9John@example.com | | 3Carol@gmail.com | +-------------------+ 2 rows in set (0.00 sec)
Here is the query to searching for an integer value in a varchar field in MySQL −
mysql> select (case when Title = 9 then 'Search Successful' else 'Search Unsuccessful' end) AS Result from DemoTable;
Output
This will produce the following output −
+---------------------+ | Result | +---------------------+ | Search Successful | | Search Unsuccessful | +---------------------+ 2 rows in set, 2 warnings (0.00 sec)
Advertisements