- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
MySQL query to return only the rows which are numeric?n
Use REGEXP to return only the numeric rows. Let us first create a table −
mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John74747'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('8494575Carol'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('985755645'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Carol-9032'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('101'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------------+ | StudentId | +--------------+ | John74747 | | 8494575Carol | | 985755645 | | Carol-9032 | | 101 | +--------------+ 5 rows in set (0.00 sec)
Following is the query to return only the rows which are numeric −
mysql> select *from DemoTable where StudentId REGEXP '^[0-9]+$';
Output
+-----------+ | StudentId | +-----------+ | 985755645 | | 101 | +-----------+ 2 rows in set (0.17 sec)
- Related Articles
- MySQL query to return only the rows which are numeric?\n
- MySQL query to group rows by the numeric characters in a string field?
- MySQL query to select top n rows efficiently?
- MySQL query to return TRUE for rows having positive value?
- MySQL query to compare and display only the rows with NULL values
- Return only a single row from duplicate rows with MySQL
- MySQL query to get the count of rows in which two or more specified values appear?\n
- How to fetch only N rows at a time in MySQL?
- MySQL query to return the count of only NO values from corresponding column value
- MongoDB query to return only embedded document?
- MySQL query to display records ordered by numeric difference?
- MySQL query to select rows where column value is only 0, group by another column?
- MySQL query to find the number of rows in the last query
- MySQL query to select too many rows?
- MySQL query to select multiple rows effectively?
- Which PHP function is used to give the number of rows affected by MySQL query?

Advertisements