I should have pointed out that the Jobs table is related to the Members 
table rather than the Family table.  I attempted  to join the member and 
job tables first and then join the member table to the family table but 
couldn't figure out how to do so.  The sample code I presented was 
intended to show how the tables are linked.  I realize now that it does 
use a join.  I didn't show my actual code assuming it might be simpler 
for a Pro to simply give me a solution that works rather than trying to 
figure out my approach.

Thanks - Joe

On Friday, February 13, 2009  9:28 AM, Stephen Russell wrote:
>
>Date: Fri, 13 Feb 2009 08:28:19 -0600
>From: Stephen Russell
>To: profoxt...@leafe.com
>cc:
>Subject: Re: SQL help for an additional level
>
>On Fri, Feb 13, 2009 at 7:45 AM, Joe Yoder <j...@wheypower.com> wrote:
>> I asked this question earlier without the Jobs component.  I now understand 
>> how to handle that one with a join but haven't figured out how to join a 
>> join.  As before this code gives me a single record but I need one for the 
>> case where there is no Typ2.
>> TIA - Joe Yoder
>>
>>  CREATE CURSOR Family (Id I)
>>  CREATE CURSOR Members (Parent I, Type C(1), Jcode C(1))
>>  CREATE CURSOR Jobs (Code C(1), Desc C(1))
>>
>>  INSERT INTO Family (Id) VALUES (1)
>>  INSERT INTO Family (Id) VALUES (2)
>>  INSERT INTO Members (Parent, Type, Jcode) VALUES (1, 'a', '1')
>>  INSERT INTO Members (Parent, Type, Jcode) VALUES (1, 'b', '2')
>>  INSERT INTO Members (Parent, Type, Jcode) VALUES (2, 'a', '3')
>>  INSERT INTO Jobs (Code, Desc) VALUES ('1', 'A')
>>  INSERT INTO Jobs (Code, Desc) VALUES ('2', 'B')
>>  INSERT INTO Jobs (Code, Desc) VALUES ('3', 'C')
>>
>>  SELECT Family.Id, M1.Type as Typ1, M2.Type as Typ2, J1.Desc as Job1, 
>> J2.Desc as Job2;
>>    FROM Family, Members as M1, Members as M2, Jobs as J1, Jobs as J2;
>>    WHERE Family.Id = M1.Parent AND M1.Type = 'a';
>>      AND Family.Id = M2.Parent AND M2.Type = 'b';
>>      AND J1.code = M1.Jcode;
>>      AND J2.code = M2.Jcode
>
>--------------------------------
>
>A good habit to get into is to USE the "join" and keep it's "on"
>conditions together.  You don't show any joins.  Not a good way to
>write SQL syntax that could be promoted to other backends is my point.
>
>
>FROM Family,
>join Members as MA
>on Family.Id = MA.Parent AND MA.Type = 'a'
>
>join Members as MB
>on Family.Id = MB.Parent AND MB.Type = 'b';
>
>join Jobs as JA
>on JA.code = MA.Jcode;
>
>join Jobs as JB
>on JB.code = MB.Jcode;
>
>You will need to create an index on Members that is compound of Parent
>and Type and Jcode.
>
>It has been a long time since I tweaked VFP indexes but you may not
>get the performance out of this if they are different data types.  Int
>/ Char.  I know that in mySQL or others this would not be an issue.
>
>Second point I changed in your code was to represent in the LETTER of
>demand in your join condition in its Name M1 is really MA same with JB
> not J2
>
>Trust me years later when you have to come back to this it will all
>look much clearer.
>
>In VFP9 can you use joins to create temp data
>
>select <field list>
>from  Members m.ID
>left join
>(
>select MA.ID, MA.Description, JA.Description
>from Members MA
>join Jobs JA
>on JA.code = MA.Jcode
>) as MemJobsA
>on M.id = MemJobsA.ID
>
>< put in stuff for the "B" here >
>
>where  < my criteria exists >
>
>I thought that I heard long ago that VFP9 sql syntax got more robust
>in this area.
>
>HTH
>
>--
>Stephen Russell
>Sr. Production Systems Programmer
>First Horizon Bank
>Memphis TN
>
>901.246-0159
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/de.1f.13570.26a95...@cm-1.zoominternet.net
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to