Quote:
|
Originally Posted by damodharan
select A.cust_cin,B.cust_address from Cust_det A, cust_add_det B
where A.Cust_cin = ? and A.cust_cin=B.cust_cin
or
select A.cust_cin,B.cust_address from Cust_det A,cust_add_det B
where A.cust_cin=B.cust_cin and A.Cust_cin = ?
|
Actually, DB2 will even apply what is called "transitive closure", by adding the condition
so the above query is essentially rewritten into
Code:
SELECT A.cust_cin,B.cust_address
FROM (SELECT cust_cin
FROM cust_det
WHERE cust_cin = ?) A,
(SELECT cust_address
FROM cust_add_det
WHERE cust_cin = ?) B
WHERE A.cust_cin=B.cust_cin
which is completely symmetric in tables A and B.
Of course, DB2 will decide on the join method and the two table accesses, based on presence of indexes and on statistics (like size of tables), hence the implementation will most often not be symmetric in the two tables.
If you are having performance issues, they will rather be solved by database changes (like adding indexes or running RUNSTATS) rather than rewriting the query.
Unless of course your query contains other ingredients than in the query above, like e.g. scalar functions in the WHERE conditions, in which case a query rewrite might be very necessary...