test=*# select * from frage;
id | t
----+-------
1 | text1
2 | text2
3 | text3
(3 rows)
test=*# select * from antwort ;
f_id | p
------+---
1 | 5
1 | 3
1 | 1
3 | 8
test=# select f.t, coalesce(sum(a.p),0) as punkte from frage f left join antwort a on (f.id=a.f_id) group by f.t order by t;
t | punkte
-------+--------
text1 | 9
text2 | 0
text3 | 8
(3 rows)
(4 rows)