New to SQL and have a query pulling some data with a number of joins across a number of tables.
Sample Data:
PERSON_NAME FUNCTION_NAME FUNCTION_ID FUNCTION_GROUP
Bob View Result 1 Editor
Bob Edit Result 4 Editor
Bob Delete Result 3 Editor
Bob Email Result 8 Editor
Mary Print Letter 45 Admin
Mary Grant Access 37 Admin
Functions have IDs, and function_groups have numerous functions. I want to query the data so instead of how it appears similar to the example above, it would look like:
PERSON_NAME FUNCTION_NAME FUNCTION_ID FUNCTION_GROUP
Bob View Result,Edit Result, Delete Result 1,4,3,8 Editor
Mary Print Letter,Grant Access 45,37 Admin
“Bob belongs to Editor, editor has the following functions” as one result, rather than the initial example, where multiple line after line is returned.
Am I correct in thinking the unique or distinct keywords can help me?
Thanks!
EDIT: Now with code
select staff_member.person_name, function.function_name,staff_group_function.function_id, staff_group.function_group_name
from staff_member
inner join staff_group
on staff_group.staff_group_id=staff_group_member.staff_group_id
inner join staff_group_function
on staff_group_function.staff_group_id=staff_group_member.staff_group_id
inner join function
on function.function_id=staff_group_function.function_group_name
Nope. What you need is
LISTAGG()if you have Oracle 11g2. This could be your query:alternatively (following your latest comment):
For any version prior to 11g2, this interesting article holds the solution for you:
http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php