I have returned records in the form:
id, group_name, {user_groupid1, user_groupid2, ..., user_groupidn}
The query returns all groups in a system plus I want to return in the same result set whether a user belongs to a group or not.
First I tried to use a subquery in the select statement to set the third column to a boolean value and it worked like charm but the big problem is that I use Java+Hibernate and Hibernate won't work with subqueries in select statements if you want to pass the result to a constructor (and that's exactly what I want). So I though of using maybe an SQL function where there are 2 parameters, the first is an ID (long), the second is an array or a set of IDs and I'd like to know whether the ID is contained in the set or not. In the example above I used a function called array_agg, so it concatenates the given IDs to an array but it's not necessarily the form the 2nd param has to be. It just a set of Ids.
Before that I came to the idea to solve this in SQL, I returned the IDs as a String array above then I processed it in Java (splitting, parsing) and I don't really like that, so that's why I need another solution.
Any help is appreciated!
cheers,
b
user,group). But I still don't understand what you are up to. If you have a list of all groups and all user_ids that belong to that group, what exactly is it you want to get out of that? I suggest you post some sample data and the expected result from that. Btw: that extraidin usergroupcontact probably doesn't make sense as (user_id, group_id) is a perfect PK unless a user can have multiples status in a group