January 12, 2009 at 1:14 pm
Hi friends,
I have 4 tables named
Places, Sessions, Periods and rules
Places -> Sessions
Sessions -> Periods
Primary Keys :
Places : Place_Id
Sessions : Session_Id
Periods : Period_Id
Rules will specify the corresponding rules on Places/Sessions/Periods/All
Sometimes, a rule is defined on Period, sometimes on Sessions, ... on Places
If a rule is defined on Places and there is no rules on Sessions and Periods,
all periods will get the same rule as on Places
if, rule is on Session and there is no rule on Places or Periods, periods will get the same rule as on session.
Even though, there are rules on Places, Sessions and Periods, Periods will get the own rule not inherited from Sessions or Places.
What is the best way to write this query.
My aim is to count the no of records in Periods table with a specific rule.
Thanks in advance
Cheers
Raj
January 12, 2009 at 1:38 pm
Write a join query that creates one row per period per rule that applies to it, give the query a Where clause, and use "select count(*)" on the query. That'll get you what you need.
The rules you outlined are the way to put the joins together.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply