
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 CONCAT a specific column value with the corresponding record
Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(100), CountryName varchar(100) ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Adam','US'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David','AUS'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris','UK'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('John','US'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Carol','AUS'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+-------------+ | FirstName | CountryName | +-----------+-------------+ | Adam | US | | David | AUS | | Chris | UK | | John | US | | Carol | AUS | +-----------+-------------+ 5 rows in set (0.00 sec)
Following is the query to concatenate a specific column value with the corresponding record −
mysql> select concat(FirstName,' ',CountryName) AS NameWithCountry from DemoTable having NameWithCountry LIKE '%John%';
This will produce the following output −
+-----------------+ | NameWithCountry | +-----------------+ | John US | +-----------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Replace a specific duplicate record with a new value in MySQL
- How to select record except the lower value record against a specific value in MySQL?
- Implement specific record ordering with MySQL
- Search record with a specific value in MySQL using LIKE or REGEXP?
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- Swap a specific column value in MySQL
- MySQL query to decrease the value of a specific record to zero?
- MySQL query to count the number of times a specific integer appears in a column for its corresponding value in another column
- Fetch a specific column value (name) in MySQL
- Delete a record with tablename.columnname= value in MySQL
- Display duplicate record as a distinct value with corresponding values as distinct comma separated list in MySQL?
- How to get the count of a specific value in a column with MySQL?
- Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL
- Add to existing value in MySQL column using CONCAT function?
- How to get a specific column record from SELECT query in MySQL?
Advertisements