Focal Point
[CLOSED] Joining same table twice

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/276101293

March 11, 2010, 05:01 PM
nsk110483
[CLOSED] Joining same table twice
Hi All,

Can I join the same table twice to join to different fields

ex:

Table A
NAME | DATE1 |

Table B
NAME | DATE2

Table C
DATE

Can I do a join like,

JOIN NAME IN TABLE A TO UNIQUE NAME IN TABLE B AS J0 END
JOIN DATE1 IN TABLE A TO UNIQUE DATE IN TABLE C AS J1 END
JOIN DATE2 IN TABLE A TO UNIQUE DATE IN TABLE C AS J2 END


Thanks,

This message has been edited. Last edited by: Kerry,


In Focus since 2008
WebFOCUS 8.2.0.1
Windows 7 - IE,Chrome,Firefox
Excel, PDF, HTML, AHTML, XML
JavaScript, jQuery, D3.js, Highcharts
March 11, 2010, 05:26 PM
Tony A
Yes you can, but you might want to use the TAG option within your joins to help identify the columns in the two TABLE C.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
March 11, 2010, 05:26 PM
Waz
Yes, but you will have to reference the columns in Table C with a prefix.

e.g.
JOIN NAME IN TABLE A TO UNIQUE NAME IN TABLE B AS J0
JOIN DATE1 IN TABLE A TO UNIQUE DATE IN TABLE C TAG T1 AS J1
JOIN DATE2 IN TABLE A TO UNIQUE DATE IN TABLE C TAG T2 AS J2

Also you need to be careful of the sort paths.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 12, 2010, 02:19 AM
Ram Prasad E
Recursive Join possible only for FOCUS or IMS data source. Either specify a unique Join Name or Use Tag names.

Here is a sample code

DEFINE FILE CAR
COUNTRY_N/A16=COUNTRY;
CAR_N/A16=IF CAR EQ 'AUDI' OR 'JENSEN' THEN 'ENGLAND' ELSE CAR;
END
TABLE FILE CAR
SUM
RETAIL_COST
BY COUNTRY_N
BY CAR_N
ON TABLE HOLD AS HLD_1 FORMAT FOCUS
END
DEFINE FILE CAR
COUNTRY_N/A16=COUNTRY;
END
TABLE FILE CAR
SUM
DEALER_COST
BY COUNTRY_N
BY CAR
ON TABLE HOLD AS HLD_2 FORMAT FOCUS INDEX COUNTRY_N
END

JOIN COUNTRY_N IN HLD_1 TO COUNTRY_N IN HLD_2 AS J1
JOIN CAR_N IN HLD_1 TO COUNTRY_N IN HLD_2 AS J2
-RUN

?FF HLD_1

TABLE FILE HLD_1
PRINT *
END



WebFOCUS 8.1.05
Windows
http://ibiwebfocus.wordpress.com
https://www.facebook.com/groups/ibi.webfocus/
March 15, 2010, 09:40 AM
jgelona
quote:
Recursive Join possible only for FOCUS or IMS data source.


Not True.

I do recursive joins with Oracle all the time. For example:

JOIN CL_CLSSN IN KDSCLINT TAG A TO CL_CLSSN IN KDSCLINT TAG B
TABLEF FILE KDSCLINT
 PRINT B.CL_CLID
    BY A.CL_CLID
 WHERE A.CL_CLID NE B.CL_CLID
    ON TABLE HOLD
END

generates this SQL

SELECT T1."CL_ID",
       T1."CL_SSN_NBR",
       T2."CL_ID"
  FROM KIDSPROD.TCLIENT T1,
       KIDSPROD.TCLIENT T2
 WHERE (T2."CL_SSN_NBR" = T1."CL_SSN_NBR")
   AND (T1."CL_ID" <> T2."CL_ID")
 ORDER BY T1."CL_ID";



In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
March 15, 2010, 11:48 AM
Francis Mariani
"Can I join the same table twice to join to different fields" is not a recursive join and Tony answered the question.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 15, 2010, 04:34 PM
Waz
quote:
Tony answered the question


Only by seconds....
Good One Tony


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 16, 2010, 03:11 AM
Tony A
quote:
Only by seconds....

... and from the opposite side of the world, how close was that!

I reckon that it was milliseconds myself because your post came up during the auto refresh upon submission, so we must have hit the button almost simultaneously.

Just goes to show ..... something, not sure what, but it definitely shows something Wink

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
March 16, 2010, 03:13 AM
Tony A
... and I think we all missed Warren's move into Virtuoso level (well, I did anyway Frowner) - well done Warren!

T
March 16, 2010, 04:30 PM
Waz
I was exiting getting close, but a non event getting there.

No Fireworks or marching bands.

It was a bit like turning 40. Big Grin


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 16, 2010, 04:34 PM
Francis Mariani
Congrats Warren!

I'm four (now three!) away from 5000 - I bet it will feel like turning 50!


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 16, 2010, 04:52 PM
njsden
Well, I am getting jealous now since I still have a looooooong way to go.

I may not have too much to celebrate by having been recently "promoted" from Gold Member to Platinum Member except perhaps for the fact that I no longer have the weird sensation of being an Austin Powers character Music

Good one to Warren ... and Francis, you're almost there!

- Neftali.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
March 16, 2010, 04:54 PM
Waz
Well, we will have to make sure that you're congratulated.

You are a pioneer, forging into unknown territory.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 16, 2010, 05:23 PM
GinnyJakes
Francis, acutally your total posts is way over 5000. Check the member directory! Way to go! Big Grin


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
March 16, 2010, 05:44 PM
Francis Mariani
And I had a different name in a previous life...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 17, 2010, 02:50 AM
Tony A
quote:
a different name in a previous life..
Plus another on an earlier board if I remember correctly.

Neftali, keep goin baby!

T
March 17, 2010, 11:17 AM
Francis Mariani
Porkpie Hat, anyone?


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 17, 2010, 01:01 PM
John_Edwards
If I dare get back on topic, consider making two passes at that table, both for the sanity of you and your future maintenance coders, and to establish better control on any multiplicative effects that could occur. Were it me I would take one pass at it for the first join, prefix every field while doing it, and then use the resulting hold file with a single join a second time.

You CAN do it with the double join, just be careful. It would be oh-so-easy to have the wrong field in a where clause.

J.

This message has been edited. Last edited by: John_Edwards,