Is it possible to group the rows of a table if the value of one of the fields is the same. Here is the request

select UP.FIO,UP.DOLQ from COM_ANKETA A left join COM_ORG_ANKETA_UP UP on UP.VNESHID=A.ID where A.ID in (:V$mainID) 

This query returns 4 rows with different FIOs, but people have the same VNESHID, and I need these people to be grouped into one string .

  • Give an example of filling the table. For something obscure. - ikoolik
  • There is a table with the ID and FIO fields for several people with the same ID and I need the query to connect the rows of the table with the same ID into one well, in short, so that people with the same ID tags are grouped together - schturman

3 answers 3

If you understand correctly, then so:

 select GROUP_CONCAT( UP.FIO ) as FIO, UP.DOLQ from COM_ANKETA A left join COM_ORG_ANKETA_UP UP on UP.VNESHID = A.ID where A.ID in (:V$mainID) group by UP.DOLQ 

PS: IMHO:

  1. Do not write table / field names - in capital letters ...
  2. The names of the tables / fields - do not make sense without a knowledge of the context (at least for me - this is a set of badly "translated" letters)
  • Either way, yes, I have never been engaged in crossing a "giraffe with an elephant," usually, reports are generated line by line with all employees indicated :) @timka_s +1 - Artem

If you want to glue the result of the query into one line, you will most likely have to use stored procedures (functions). Just do not know how to them in mysql.

  • Duck yes you need to group roughly speaking by ID. I cannot understand how to do it - schturman

That's about how I need and I need

This is a worthwhile knowledge in order to properly ask a question! I need it, but I need it so . Great and powerful Russian language.

 SELECT ID,FIO FROM table WHERE ID='999'; 

Will you get everyone with ID 999 with this? Well, if you want just one line to be only in the loop after the request, but is there any point in this?

Take and bring everyone in the loop and do whatever you want with them.

For the future, the right question is 90% that the answer will be just as correct and quickly written.

// upd This query returns 4 rows with different FIO, but people have the same VNESHID, and I need these people to be grouped into one string.

So look, you get the correct data, just you process it correctly in a loop then

 $q="select UP.FIO,UP.DOLQ from COM_ANKETA A left join COM_ORG_ANKETA_UP UP on UP.VNESHID=A.ID where A.ID in (:V$mainID)"; $res=mysql_query($q); while($row=mysql_fetch_array($res)) { echo $row['UP.FIO']."<br />"; } 

Well, then do what you want, you want in one line, you want in two, three, five, ten.

  • And how in the loop after the request to do it. There is a sense in this and how to "pull out" everyone with the same ID. I know you need a query for grouping by the same ID, and I have a query like this select UP.FIO, UP.DOLQ, UP.ADRES from COM_ANKETA A left join COM_ORG_ANKETA_UP UP on UP.VNESHID = A.ID where A.ID in (: V $ mainID) and in the COM_ORG_ANKETA_UP tab. It is necessary to group the founders by VNESHID so that they are displayed in one field, but now they are displayed in different and as a result a very large report is obtained, since There is a lot of data besides this I pull out. - schturman
  • Update your question correctly, with all the fields with all the tables, with all the conditions, competently issue, and I haven’t even finished reading your comment, it’s hard to read something that is not readable. - Artem
  • updated can be so clearer what I want guys help pliz I really broke my head - schturman
  • ĂŞĂ Ă® nonsense some kind of it turns out no one can understand me that I want well all thanks for the help I will google further I can find something - schturman
  • You wrote 2 answers. If you can’t express what you want, then how we "psychics" should understand you. - Artem