How to join chains in MySQL?

1

I am trying to unite the name, paternal surname and maternal surname having for example a result like this: "Juan López Robles" we see how to start each word is a capital letter and follow the lower case followed by a space and so on with the other words. What I have is this:

select id_empleado, 
       concat((concat(upper(left(nombre,1)),lower(substring(nombre,2))),' '), 
       concat(concat((upper(left(apellido_paterno,1)),lower(substring(apellido_paterno,2)))),' ')), 
       concat((upper(left(apellido_materno,1)),lower(substring(apellido_materno,2)))) 
       as nombre from empleado where id_empleado = 1

But I do not know how to join the concat try using concat () too but I returned the error:

  

Error Code: 1241. Operand should contain 1 column (s)

I hope you can help me thanks for your answers.

    
asked by U.C 25.07.2017 в 17:22
source

2 answers

1

If you use MYSQL you can use CONCAT_WS(" ",apellido_paterno,apellido_materno,nombre)

    
answered by 25.07.2017 в 17:28
1

Use CONCAT_WS that receives as a first parameter a separator that joins each one of the received parameters:

SELECT CONCAT_WS("-", "es", "en", "fr"); // imprime: es-en-fr

In your case it would be:

SELECT CONCAT_WS(" ", nombre, apellido_paterno, apellido_materno) as nombreCompleto from empleado where id_empleado = 1
    
answered by 25.07.2017 в 19:35