tryng to select table rows and then use subqueries to generate single row list (item1,item2,item3)
anyway sql:
select
username,
concat(firstname || ' ', lastname) as name,
email,
phone,
(
select
ltrim(sys_connect_by_path(res, ', '), ', ')
from (
select
count(*) over() as cnt,
row_number() over(order by ofield) as rnum,
(select name from rooms where code=roomcode) as res
from adminrooms
where roomcode=admins.code) /*admins.code - come from main query but it gives error: invalid identifier*/
where cnt=rnum start with rnum=1 connect by prior rnum=(rnum-1)
) as groups
from admins
where frozen=0 and (type <> 'root' or type is null)
problem seems to be the main query field ‘code’ from table ‘admins’ don’t work inside list generation query
Based on your db diagram, the best way to do it is to use a custom string aggregation function and then just do a group by. This is similar to mysql group_concat.
If you make a function called string_agg() using the above link, you can use it as below in your code:
Here is the string_agg function create script. Just run this as a script and you will have the function above (taken from the link shown above):