
- 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
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 Articles
- 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?
- Search record with a specific value in MySQL using LIKE or REGEXP?
- Implement specific record ordering with MySQL
- 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
- How to get a specific column record from SELECT query in MySQL?
- Add to existing value in MySQL column using CONCAT function?
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Fetch a specific column value (name) 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?
- Find rows where column value ends with a specific substring in MySQL?

Advertisements