- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 MySQL CONCAT() function, applied to the column/s of a table, can be combined with the column/s of other tables?
We can use the output of CONCAT() function which is applied to the column/s of a MySQL with the column/s of another MySQL table. It can be done with the help of MySQL join.
Example
For example, we have two table ‘Student’, having the details like id, Name, Last_name, Address and Subjects of the students, and ‘Remarks’, having the id and comments about the students. Now, the following query can combine CONCAT() function with another table column −
mysql> Select * from remarks; +------+-------------+ | ID | Comment | +------+-------------+ | 1 | Good | | 2 | Excellent | | 15 | Average | | 20 | Good | | 21 | Outstanding | +------+-------------+ 5 rows in set (0.00 sec) mysql> Select CONCAT(Name,' ' ,Last_Name ), Comment from student s, remarks r -> Where s.id = r.id; +------------------------------+-------------+ | CONCAT(Name,' ' ,Last_Name ) | Comment | +------------------------------+-------------+ | Gaurav Kumar | Good | | Aarav Sharma | Excellent | | Harshit Kumar | Average | | Gaurav Rathore | Good | | Yashraj Singh | Outstanding | +------------------------------+-------------+ 5 rows in set (0.00 sec)
Both the tables are joined on the basis of common ‘id’ of the students in both the tables.
Advertisements