I have 2 tables:
users:
id
------
1
permissions:
id | action | userId
---|--------|--------
1 | read | 1
2 | write | 1
When I run the following query (return users with its permissions):
select
users.*,
(string_agg(permissions.action::text, ',') as permissions
from
"users"
join "permissions" "permissions" on
"userId" = "users"."id"
and "userId" = 1
group by
"users"."id"
order by
"users"."id" asc
limit 1
I get:
id | permissions
---|-------------
1 | read,write
Which is great (this is what I need) but I expected it to return:
id | permissions
---|-------------
1 | read
Because of the query has limit 1
constraint.
Anyone can shed some light on what happens in the background?
permissions
table with proper ordering and limiting.