OT: SQL question

6 views
Skip to first unread message

Michael Lackhoff

unread,
Nov 21, 2009, 11:15:26 AM11/21/09
to rose-db...@googlegroups.com
Hello,

I would like to improve performance of my app and a very good candidate
for this is an object that has lots of relationships due to
normalization and is the most used object which leeds to quite a few db
hits.

My idea was to create a view where the typically needed fields are taken
from the related tables but I am by no means an SQL expert and hope that
it is not too much frowned upon if I ask an SQL question here.
What I need are a few many to one relationships and an aggregate
function over a many to many relationship. I got the aggregate working
but as soon as I add the where clauses for the many to one relationships
I get far too more records into the sum

I started with this select that eventuelly gives the select for the view
(I will need to integrate two more relationships but want to keep it
simple):
SELECT
b.nr AS nr,
t3.nachname AS name,
SUM(t2.dauer) AS dauer
FROM
mapping_table t1,
mapping_target t2,
many_to_one_target t3,
main_table b
WHERE
b.nr = 49405 AND -- an example id to test with
b.nr = t1.behandlung_id AND -- these three are needed for the
t1.preisliste_vom = t2.gilt_ab AND -- many to many
t1.praxis_id = t2.praxis_id AND -- relationship
b.client_id = t3.nr
GROUP BY b.nr;

as I said, without the t3 lines everything looks all right. What am I
missing?

The second question is more RDBO and RHTML (forms) related: Is it
possible to somehow use the view (if I manage to build it) for
reading/display and the original object for writing?

Thanks,
-Michael
Reply all
Reply to author
Forward
0 new messages