In a query Is it possible to fill a field with all the records of another table?

1

I am making a query and in a field of that query I want to concatenate or extract all the data that is in another table. Is it possible to do this?

This is the query I'm doing:

SELECT r.id_resg as 'CLAVE RESGUARDO',

       -- AQUI QUISIERA QUE SALIERAN TODOS LOS CAMPOS DE MI OTRA TABLA,
       concat(resp.id_personal,' ' ,p.nombre,' ',p.Puesto) as 'RESGUARDANTE(S)'

  from articulos art 
  join art_resguardo artresg 
  join resguardos r 
  join responsables resp 
  join personal p 
    on r.id_resg=resp.id_resg 
   and resp.id_personal=p.id_personal 
   and art.no_serie=artresg.no_serie 
   and r.id_resg=artresg.id_resg;
    
asked by MARCO 05.11.2016 в 22:18
source

2 answers

0

In MySQL at least you can. I do not know which database engine you are using because it is not clear in your question.

In the case of MySQL the syntax would be something like this

INSERT INTO 'tabla_donde_quieras_insertar' ('clave_resguardo', 'resguardantes')
SELECT
    r.id_resg as 'clave_resguardo',
    CONCAT(...) as 'resguardantes'

FROM
    ...

WHERE
    ...

Make sure that the query is well done, since from there you will have to take out the password_rescue and resguardantes (I have changed the name to how I think it will have to be called the field in database)

    
answered by 06.11.2016 в 11:19
0

Now solve my problem use the GROUP_CONCAT to concatenate all the rows of a table together with a where clause to restrict only those that I occupy. Thanks for your answers

    
answered by 08.11.2016 в 05:39