Thanks Ricardo - The code you suggest gives me some ideas of how to approach the combined statement. Unfortunately there are apparently some errors in the code that I have not been able to correct. I like the way you broke up the statement to make it understandable but I'm afraid it will need to work before I really understand it.
Thanks again - Joe On Saturday, February 14, 2009 11:23 PM, Ricardo Aráoz wrote: > >Date: Sun, 15 Feb 2009 01:23:08 -0300 >From: Ricardo Aráoz >To: [email protected] >cc: >Subject: Re: Simplest form of SQL? > >Joe Yoder wrote: >> Here is the code I've been trying to reduce to a single SQL select. It >> works fine as is but I'm trying to understand if there is a way to do it in >> a single statement. Perhaps this is already the simplest approach? >> >> 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), Jdesc 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, Jdesc) VALUES ('1', 'A') >> INSERT INTO Jobs (Code, Jdesc) VALUES ('2', 'B') >> INSERT INTO Jobs (Code, Jdesc) VALUES ('3', 'C') >> >> SELECT * FROM Members LEFT JOIN Jobs ON Jcode == Code INTO CURSOR MC >> >> SELECT Family.Id, M1.Type as Typ1, M2.Type as Typ2, M1.Jdesc as Job1, >> M2.Jdesc as Job2; >> FROM Family LEFT JOIN MC as M1 ON Id == M1.Parent AND M1.type = 'a'; >> LEFT JOIN MC as M2 ON Id == M2.Parent AND M2.type = 'b' >> >UNTESTED : > >SELECT Family.Id, M1.Type as Typ1, M2.Type as Typ2, M1.Jdesc as Job1, M2.Jdesc >as Job2; > FROM Family ; > LEFT JOIN (; > SELECT * ; > INTO CURSOR MC; > FROM Members ; > LEFT JOIN Jobs ; > ON Jcode == Code ; > ) M1 ; > ON Id == M1.Parent AND M1.type = 'a'; > LEFT JOIN (; > SELECT * ; > INTO CURSOR MC; > FROM Members ; > LEFT JOIN Jobs ; > ON Jcode == Code ; > ) M2 ; > ON Id == M2.Parent AND M2.type = 'b' > > > [excessive quoting removed by server] _______________________________________________ Post Messages to: [email protected] 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/[email protected] ** 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.

