Mysql - Create an alias by concatenating multiple fields

Asked

Viewed 180 times

2

Is it possible to create an alias by concatenating other fields? Ex:

SELECT u.nome, u.sobrenome AS nome_completo
FROM usuarios u

In the example, I want to concatenate u name. and u surname. and store in the field full name.

3 answers

5


SELECT CONCAT(u.nome,' ', u.sobrenome) nome_completo
FROM usuarios u

4

SELECT u.nome + ' ' + u.sobrenome AS nome_completo FROM usuarios u

or

SELECT CONCAT(u.nome + " " + u.sobrenome) AS nome_completo FROM
usuarios u;

3

Another way to do that would be this:

SELECT CONCAT_WS(" ", u.nome, u.sobrenome) AS nome_completo FROM usuarios u;

The difference with CONCAT is that the separate is defined in the first parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.