
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Concatenating two strings in MySQL with space?
For this, you can use concat() function from MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> Subject varchar(100) -> ); Query OK, 0 rows affected (17.73 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Name,Subject) values('John','MySQL'); Query OK, 1 row affected (1.19 sec) mysql> insert into DemoTable(Name,Subject) values('Chris','SQL Server'); Query OK, 1 row affected (0.88 sec) mysql> insert into DemoTable(Name,Subject) values('Robert','MongoDB'); Query OK, 1 row affected (2.62 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+--------+------------+ | Id | Name | Subject | +----+--------+------------+ | 1 | John | MySQL | | 2 | Chris | SQL Server | | 3 | Robert | MongoDB | +----+--------+------------+ 3 rows in set (0.00 sec)
Here is the query to concatenate two strings with space −
mysql> update DemoTable -> set Subject=concat(Name,' ',Subject); Query OK, 3 rows affected (0.38 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check all records from the table −
mysql> select *from DemoTable;
Output
+----+--------+------------------+ | Id | Name | Subject | +----+--------+------------------+ | 1 | John | John MySQL | | 2 | Chris | Chris SQL Server | | 3 | Robert | Robert MongoDB | +----+--------+------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to add two strings with a space in first string in JavaScript?
- Comparing two strings in MySQL?
- Remove space between two words in MySQL?
- Check whether given string can be generated after concatenating given strings in Python
- Python – Filter rows without Space Strings
- Can MySQL concatenate strings with ||?
- Python - Custom space size padding in Strings List
- In MySQL, how can I combine two or more strings along with a separator?
- How to add two or more strings in MySQL?
- How to check similarity between two strings in MySQL?
- MySQL ORDER BY strings with underscore?
- How do I replace “+”(plus sign) with SPACE in MySQL?
- Adding/ concatenating text values within a MySQL SELECT clause?
- How to compare two strings which are numbers in MySQL?
- Concatenating Files in Linux

Advertisements