Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get first name and last name as whole name in a MYSQL query?

Tags:

I want to be able to do something like this

SELECT `first_name` + " " + `last_name` as `whole_name` FROM `users` 

So basically I get one column back whole_name which is first_name and last_name concatenated together with a (space).

How do I do that in SQL, or more specifically, MySQL ?

like image 363
alex Avatar asked Jul 15 '10 00:07

alex


People also ask

How can I get first name and last name in mysql?

SELECT Concat(Ifnull(FirstName,' ') ,' ', Ifnull(MiddleName,' '),' ', Ifnull(Lastname,' ')) FROM TableName; If anyone containing null value the ' ' (space) will add with next value.

How do I combine first name and last name in SQL query?

1. select FirstName +' '+ MiddleName +' ' + Lastname as Name from TableName.

How do you get names to start and end with vowels in SQL?

To check if a name begins ends with a vowel we use the string functions to pick the first and last characters and check if they were matching with vowels using in where the condition of the query. We use the LEFT() and RIGHT() functions of the string in SQL to check the first and last characters.


1 Answers

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws

SELECT CONCAT_WS(" ", `first_name`, `last_name`) AS `whole_name` FROM `users` 
like image 153
Borealid Avatar answered Sep 19 '22 04:09

Borealid