- 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
How do I split a numerical query result in MySQL?
To split a numerical query result, you can use the CONCAT() function in MySQL. Let us first create a table −
mysql> create table DemoTable ( StudentId int ); Query OK, 0 rows affected (0.68 sec)
Now you can insert some records in the table using insert command −
mysql> insert into DemoTable values(2222); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(5555); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(4567); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(8905); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-----------+ | StudentId | +-----------+ | 2222 | | 5555 | | 4567 | | 8905 | +-----------+ 4 rows in set (0.00 sec)
Following is the query to split a numerical query result. Here, we have split the first digit of the value −
mysql> select concat(left(StudentId, 1), '/',right(StudentId, length(StudentId)-1)) splitNumericalValue from DemoTable;
Output
+---------------------+ | splitNumericalValue | +---------------------+ | 2/222 | | 5/555 | | 4/567 | | 8/905 | +---------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How can I display MySQL query result vertically?
- How do I write not greater than in a MySQL query?
- How to store Query Result in a variable using MySQL?
- How do I insert multiple values in a column with a single MySQL query?
- How do I query a MongoDB collection?
- How to assign the result of a MySQL query into a variable?
- How do I split a string, breaking at a particular character in JavaScript?
- MySQL query to split a column after specific characters?
- How do I split a multi-line string into multiple lines?
- Set the result of a query to a variable in MySQL?
- How do I detect if the ON UPDATE event fired with query in MySQL?
- Calculating percentage in a MySQL query and round off the result
- How can I stop running a MySQL query?
- How can I stop a running MySQL query?
- Set user variable from result of query in MySQL?

Advertisements