Concatenate string with numbers in MySQL?

MySQLMySQLi Database

To concatenate string with numbers, use the CONCAT() method. Let us first create a table −

mysql> create table DemoTable682(
   Name varchar(100),
   Age int
);
Query OK, 0 rows affected (0.49 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable682 values('John',23);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable682 values('Chris',21);
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable682 values('David',25);
Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement:

Display all records from the table using select statement -

mysql> select *from DemoTable682;

This will produce the following output −

+-------+------+
| Name  | Age  |
+-------+------+
| John  |   23 |
| Chris |   21 |
| David |   25 |
+-------+------+
3 rows in set (0.00 sec)

Following is the query to implement concat() method to concatenate records −

mysql> select concat(Name,Age) from DemoTable682;

This will produce the following output −

+------------------+
| concat(Name,Age) |
+------------------+
| John23           |
| Chris21          |
| David25          |
+------------------+
3 rows in set (0.00 sec)
raja
Published on 26-Aug-2019 11:04:42
Advertisements