sql - MS Access Data Structure Problems with Parent/Child self-joins -
i have database following tables:
beliefst
- beliefid (autonumber)
- belief (short text)
reasonstoagreet
- argagreeid (autonumber)
- conclusionaid(lookup beliefst)
- reasontoagreeid (also lookup beliefst)
reasonstodisagreet
- argdisagreeid (autonumber)
- conclusiondid (also lookup beliefst)
- reasontodisagreeid (also lookup beliefst)
problem 1: can't count number of times conclusionaid has been selected in reasonstoagreet table.
this first attempt:
select beliefst.belief, reasonstoagreet.reasontoagreeid, reasonstodisagreet.reasontodisagreeid (beliefst left join reasonstoagreet on beliefst.beliefid = reasonstoagreet.conclusionaid ) left join reasonstodisagreet on beliefst.beliefid = reasonstodisagreet.conclusiondid group beliefst.belief, reasonstoagreet.reasontoagreeid, reasonstodisagreet.reasontodisagreeid order beliefst.belief;
it sort of lets @ values, doesn't anything...
i can @ 1 table @ time, doesn't me anything:
select reasonstoagreet.conclusionaid, count(reasonstoagreet.reasontoagreeid) countofreasontoagreeid reasonstoagreet group reasonstoagreet.conclusionaid;
this closesest can get, report data source, counts duplicate empty values, because relationships messed up:
select beliefst.belief, reasonstoagreet.reasontoagreeid, reasonstodisagreet.reasontodisagreeid (beliefst left join reasonstoagreet on beliefst.beliefid = reasonstoagreet.conclusionaid ) left join reasonstodisagreet on beliefst.beliefid = reasonstodisagreet.conclusiondid;
when include both reasons agree table , reasons disagree table, relationships messed up, because both @ same belief table, , tries cross product, , gets messed up, , can't accurately count number of reasons agree or disagree...
your business logic , problem definition bit unclear, based on qualified guess, best possible sql query solution came out following:
select beliefst.belief, reasonstoagreet.reasontoagreeid, reasonstodisagreet.reasontodisagreeid (beliefst left join reasonstoagreet on beliefst.beliefid = reasonstoagreet.conclusionaid) left join reasonstodisagreet on beliefst.beliefid = reasonstodisagreet.conclusiondid;
if problem null
values erroneously counted, add where
clause not null
referring respective fields. option use ms access sql conditional operator iif(isnull(somefield), 0, 1)
.
hope may help. best regards,
Comments
Post a Comment