I have this query, then i need to obtein from there the distinct set of the rows. The problem is that the whole execution plan is changed and the tables in query 1 searched entirely if the distinct clause is include. My intension is to execute the distinct but just in the result of query1. Any way to force that?
SELECT ( LTrim(RTrim(MOC_OHNUMBER)) || '_' || LTrim(RTrim(MOC_REF_NO))) RQ_JobLot, MOC_OHNUMBER, MOC_REF_NO
WHERE RPAD(LTrim(RTrim(MOC_OHNUMBER)) || '_' || LTrim(RTrim(MOC_REF_NO)), 55, ' ') IN
SELECT RPAD(LTrim(RTrim(RQ_MOSJOB)) || '_' || (LTrim(RQ_MOSLOT, '0')), 55, ' ') RQ_JobLot
FROM MatQry_7 LotMaterials