Tags

, , ,

In DB2, we often use the predicate EXISTS to verify if a row is present 
in a table based on our required criteria.  We do not wish to get any 
data from the table being read on the right side of EXISTS, we just 
want to see if some row is present or not.
In this case, EXISTS should be coded as
SELECT A,B,C FROM TABLE1
WHERE
D EXISTS
(
SELECT 'X'
FROM
TABLE2
);
Note: X can also replace a column name from TABLE2
In the existing code, you might see EXISTS used as below, where the 
complete matching data (by using SELECT *) from TABLE2 is obtained, 
to check for its existence. We will have performance degradation here. 
We need to ensure to have the code as the above example, where we get 
only a constant or single column.
SELECT A,B,C FROM TABLE1
WHERE
D EXISTS
(
SELECT *
FROM
TABLE2
);

Important SQL CODES and ABEND CODES
SORT JOIN – TO JOIN TWO FILES BASED ON A KEY
KNOW YOUR MAINFRAME
REXX – INITIAL SETUP
DB2 SQL Query to read COMP (COBOL) data stored in CHAR column
DB2 Performance – Using SET vs SYSDUMMY1 table
DB2 Performace – Predicates Processing Order
DB2 External Stored Procedures
DB2 UPDATE QUERY – UPDATE TABLE1 FROM TABLE2 DATA
DB2 PERFORMANCE ISSUE (When using EXISTS)
HOW DOES DB2 INTERNALLY (PHYSICALLY) STORE THE DATA
HOW DO YOU FIND WHO HAS ACTUALLY LOADED THE DB2 TABLE RECENTLY
TERMINATE A STOPPED DB2 UTILITY
SELECT UNIQUE RECORDS USING “GROUP BY”
DB2 and SQL INTERVIEW QUESTIONS
DB2 TIPS
Optimistic Locking vs. Pessimistic Locking
DB2 BIND OPTIONS and ISOLATION
Is SCHEMA name necessary for DYNAMIC QUERY
DB2 SQL – REPLACE CHARACTERS WITH ACCENTS (NON ENGLISH ALPHABETS)
Advertisements