Hello.
The following SQL query is running fine when executed on console to retrieve the names of those groups acting as parents of another group:
SELECT g.id, group_name, role, parent_id,
(SELECT group_name FROM groups p WHERE g.parent = p.id) AS parent_group
FROM groups g
JOIN user_groups ON user_groups.id_group = g.id
JOIN roles ON user_groups.id_role = roles.id
WHERE user_groups.id_user= 3 ;
And it results in a table such as the following one:
id | group_name | role | parent_id | parent_group
----+----------------+-------+-----------+--------------
8 | Test group | Owner | |
9 | Another group | Owner | |
12 | A subgroup | Owner | 8 | Test group
(3 rows)
However, this same SQL query doesn't run within a fRecordSet::buildFromSQL() call, resulting in the error message 'The SQL statement specified ... does not appear to be in the form SELECT * FROM table'.
Changing the query to: "SELECT *, (SELECT group_name FROM groups p WHERE g.parent = p.id) AS ..." doesn't make any difference, so it looks as the second SELECT is causing the problem.
BTW, the table doesn't have any foreign key self-referencing itself (not all groups have a parent group), and any self-join constructed query returns only the groups having a parent.
There would be any other way to get this recordset built?
A.