Question

I have a CASE_MEMBER table with a row for each case member, and a field to indicate the member's role on the case. Let's say role 'Parent' and role 'Child'.

In the universe I've added the CASE_MEMBER table, and created a Parent object and Child object, each object containing a WHERE statement which specifies the correct value of the role field.

Now if I try and create a report with both of these objects, it will join to CASE_MEMBER only once, with a condition of "where role = 'Parent' and role = 'Child'", which is obviously impossible.

So I need to force the query to join to CASE_MEMBER once for each member type. Is the only way to do this by creating multiple aliases of CASE_MEMBER? Or is there another way to do this that also keeps my universe structure looking clean and more resembling the actual data model?

Was it helpful?

Solution

Create an alias of CASE_MEMBER, and include the WHERE condition in the join. So your joins will be:

For CASE_MEMBER to DEMOGRAPHICS:

case_member.member = demographics.memberid and case_member.role='child'

For CASE_MEMBER to DEMOGRAPHICS_PARENT (alias of DEMOGRAPHICS):

case_member.member = demographics_parent.memberid and case_member.role='parent'

Let's say you create (using the field names from your other question), a "Case ID" object from case_member.caseid, "Child SSN" from demographics.ssn, and "Parent SSN" from demographics_parent.ssn. Creating a report with all three of these objects will produce:

SELECT
   case_member.caseid,
   demographics.ssn,
   demographics_parent.ssn
FROM
   case_member,
   demographics,
   demographics demographics_parent
WHERE
   (case_member.member = demographics.memberid 
        and case_member.role='child')
   (and case_member.member = demographics_parent.memberid 
        and case_member.role='parent')

which should produce what you want.

Note that in this example, since we are including BOTH the child and parent table, we will get two rows in the result set. One with a blank child SSN and one with a blank parent SSN. To avoid this, you'd need to put a max() around each one.that

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top