need to combine group-by and right-outer-join.
TableA has groups "a", "b", "c", "d"
TableB has: 12|a, 2|b, 1|a 5|b 3|d several times.
I group TableB as view by the group like this:
ViewB: 13|a 7|b 3|d
As you can see, group "c" is not in the TableB and not in the ViewB. I need some outer join like this:
ViewB 13|a 7|b 3|d null|c
how can i achive that?
UPDATE. I see, that this simple example does not describe the complexity. Additionaly i have third Table "Users" So group for each user, for each TableA-Values. Example
userA| 13| a
userA| 7 | b
userA| 3 | d
userB| 10| a
userB| 70 | b
userB| 30 | d
Group "c" is not in the TableB (TableB contains values for the groups) When i try query like this:
select
right outer join TableA
on TableB.id = TableA.id
join TableC
on TableB.other_id = TableC.other_id
group by TableB.groups
I just get something like this:
null| null| c
userA| 13| a
userA| 7 | b
userA| 3 | d
userB| 10| a
userB| 70 | b
userB| 30 | d
But i need:
|userA| 13| a
|userA| 7 | b
|userA| 3 | d
|userA| NULL| c
|userB| 10| a
|userB| 70 | b
|userB| 30 | d
|userB| NULL | c
UPDATE_2 Sorry for less informations. I use oracle g11 Here is the links for example-schema:
http://sqlfiddle.com/#!4/71069
My Sql-Query, which should be extented looks like this:
SELECT usr.user_name,
SUM (lg_all.new_values) AS group_sum,
allw.group_name
FROM users usr, products lg_all, myGroup allw
WHERE usr.user_id = lg_all.user_id
AND allw.group_id = lg_all.group_id
GROUP BY (usr.USER_ID, allw.group_name)
ORDER BY usr.LOGONUSER_ID DESC
My result looks like this:
userA| 13| a
userA| 7 | b
userA| 3 | d
userB| 10| a
userB| 70 | b
userB| 30 | d
But i need:
|userA| 13| a
|userA| 7 | b
|userA| 3 | d
|userA| NULL| c
|userB| 10| a
|userB| 70 | b
|userB| 30 | d
|userB| NULL | c
Thx.