Focal Point
Antijoin in master-file. Can I define something like NOT EXISTS?

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

July 03, 2007, 05:05 AM
Ingas
Antijoin in master-file. Can I define something like NOT EXISTS?
Hi all

I can't find a possibility to define in master file something like:

SELECT Customer_id FROM Sales S
WHERE
NOT EXISTS(
SELECT customer_id FROM customer C
WHERE
S.customer_id = C.customer_id
)

(Find all incorrect record in sales table for nonexistent customer)

I do no see such option in WF-joins
Also I saw a filter function EXCLUDES - but it's more like NOT IN (...)

Maybe I'm mistaken - can somebody guide me in right direction?


WF 7.6.2, WinNT/2K, MSSQL 2K, MSOLAP 2K, BID
July 03, 2007, 08:08 AM
Tony A
I do not think that you can achieve what you want within the master file description using DEFINEs - someone will now prove me wrong. You certainly can not use SQL statements.

You could try
JOIN CLEAR *
JOIN LEFT_OUTER Customer_id IN Sales TAG S TO customer_id IN customer TAG C AS J1.
TABLE FILE Sales
PRINT S.Customer_id
WHERE C.customer_id IS MISSING
END

or you could include the SQL within the focexec itself using SQL passthru, many examples of which exist in the many topics and posts on this forum.

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 
July 03, 2007, 08:37 AM
Ingas
Yes, I know that I can't use SQL in master file definitions.
In fact, I've asked about equivalent Focus statement.
(I'm novice in Focus)

Thank you for your advice, in fact it's equivalent in SQL to:

SELECT S.Customer_id
FROM
SALES S
LEFT OUTER JOIN customer C ON S.customer_id = S.customer_id
WHERE
C.customer_id IS NULL

It's equivalent to NOT EXISTS statement, but from my experience NOT EXISTS sometimes works faster then LEFT OUTER JOIN (in MSSQL)
I've thought in Focus exists something like antijoin.

(Now I'm looking for something like Oracle antiunion - select from multiple sources only different records)

SQL Passthru - is not possible when sources from different connections.


WF 7.6.2, WinNT/2K, MSSQL 2K, MSOLAP 2K, BID
July 03, 2007, 09:10 AM
mgrackin
Ingas,

There is no way that I know of to write FOCUS code that will translate into SQL code that contains a subquery in a WHERE clause. IBI Tech Support would be the best people to ask about this but I have never seen this in any information I have read about FOCUS to RDBMS efficiencies.

I'm not sure what this will translate to as far as SQL but this is another way to accomplish the same thing. Be careful of the limits on how many values can be in the VALIDVALUES file. The limit with an IF selection is 32,767 according to the WF 7.1 manual. This will create a large SQL request depending on how many values there are in the VALIDVALUES list.

TABLE FILE CAR
SUM COUNTRY NOPRINT
BY COUNTRY
WHERE COUNTRY EQ 'ENGLAND' OR 'W GERMANY'
ON TABLE SAVE AS VALIDVALUES
END
-RUN
TABLE FILE CAR
PRINT COUNTRY CAR MODEL BODYTYPE
IF COUNTRY IS-NOT (VALIDVALUES)
END


Thanks!

Mickey

FOCUS/WebFOCUS 1990 - 2011
July 03, 2007, 10:52 AM
j.gross
For a 1-1 join, you can define fields based on the values in the virtual (joined-to) segment, and the define will be evaluated whether or not an actual instance is located, as though an instance had been retieved whose fields are all blank or zero.

JOIN COUNTRY IN HOLD TO COUNTRY IN CAR
DEFINE FILE HOLD
TAKE/I1 = CAR.ORIGIN.COUNTRY EQ ' ';
END
TABLE FILE HOLD
PRINT *
IF TAKE IS TRUE
END


- Jack Gross
WF through 8.1.05
July 04, 2007, 08:25 AM
Ingas
Thanks to all for help!

I've understood how this can be accomplished.

LEFT OUTER JOIN and IS MISSING is what I've search

Variant with virtual field, then filtering this field - also looks good for me


WF 7.6.2, WinNT/2K, MSSQL 2K, MSOLAP 2K, BID
July 04, 2007, 06:50 PM
GCohen
I believe the easiest way to do this is to use the 'ALL' operation.

JOIN CUSTOMER_ID IN SALES TO CUSTOMER_ID IN CUSTOMER
TABLE FILE SALES
PRINT ALL CUSTOMER_ID
WHERE CUSTOMER.CUSTOMER_ID IS MISSING ;
END


Release 7.6.9
Windows
HTML
July 04, 2007, 06:51 PM
GCohen
Forgot to add the 'dot.
Make it PRINT ALL.CUSTOMER_ID


Release 7.6.9
Windows
HTML
July 05, 2007, 09:39 AM
jgelona
And of course, there's always MATCH.

MATCH FILE SALES
SUM SALE_TOTAL
BY CUSTOMER_ID
RUN
FILE CUSTOMER
SUM CUSTOMER_NAME
BY CUSTOMER_ID
AFTER MATCH HOLD OLD-NOT-NEW
END


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
July 05, 2007, 10:22 AM
mgrackin
MATCH FILE will work but will probably pull all the data from the RDBMS over to FOCUS before trying to compare. That will take a LOOONNNGGG time.


Thanks!

Mickey

FOCUS/WebFOCUS 1990 - 2011
July 06, 2007, 09:16 AM
jgelona
Mickey,

True, it could take a long time depending on the number or rows in each table. However, assuming this is a relational database, having a foreign key relationship between the 2 tables eliminates the need for the query because one could not insert a row the SALES table before the customer was added to the CUSTOMER table.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.