MySQL: Read values from two columns and output them in a single variable
Tip by Computer Expert | Last update on 2021-03-08 | Created on 2012-07-02
An interesting MySQL command allows us to read values from two or more columns to output them along with any other string in only one single variable, just like as if the values are coming from one separate column. The command is called CONCAT.
An Example
As an example, we have two columns: one is called "firstname" and the other is called "lastname". We now want to read out the first and last names together and put a space between them. The MySQL query with CONCAT is the following:
SELECT CONCAT(firstname, ' ', lastname) FROM tab WHERE id=100;
As a result we get, for example, "Anna Backer" and we do not have to worry about joining the two strings "firstname" and "lastname" after reading the values from our database.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
PHP: Write Output of a Script into Variable
Tutorial | 0 Comments
MySQL: 3 Ways of showing Table Definition and Structure
Info | 0 Comments
Delphi/Lazarus: Display current Date and Time
Tip | 0 Comments
jQuery: Send HTML5 Canvas to Server via Ajax
Tutorial | 0 Comments
MySQL: Delete Data from Table - Difference between TRUNCATE, DELETE and DROP
Tutorial | 0 Comments
PHP: Send Output of a Script by Mail
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.