There is a multi-level list of floors and classrooms on each floor in the building. In this list there is a floor ID = 1 and office ID = 2.

app_global_lists_choices +----------------+----+-----------+ | name | id | parent_id | +----------------+----+-----------+ | 1 этаж | 1 | 0 | | Кабинет УЗИ | 2 | 1 | | Кабинет ЭКГ | 3 | 1 | | 2 этаж | 4 | 0 | | Кабинет ЛФК | 5 | 4 | +----------------+----+-----------+ 

The request is implied:

 $sql = "select name from app_global_lists_choices where id in (1,2)" 

returns the floor number and the name of the cabinet.

In fact, only the name of the first value is returned (1st floor). The second disappears without a trace.

Is it possible to return the request in this form:

 1 этаж / Кабинет УЗИ 
  • one
    usually throw the structure of the table (s) a couple of lines for an example .. - sterx

1 answer 1

With all the idiocy of the solution, it will work:

 SELECT REPLACE(GROUP_CONCAT(name ORDER BY id), ', ', ' / ') FROM app_global_lists_choices WHERE id IN (1,2) 
  • Thank you so much, it works! Although there is one BUT! I intend to simplify the task by deciding that it will not affect the final result. And no, influenced. In fact, the query I described is a subquery, and the values ​​of 1.2 are generated by another query. The parental request "links" the doctor’s name to the cabinet. In general, it looks like this: SELECT REPLACE (GROUP_CONCAT (name ORDER BY id), ',', '/') FROM app_global_lists_choices WHERE id IN (select field_2 from app_entity_1 where id = created_by) And in this form it returns only "1 floor " - Kriko Talle