I need to ‘manufacture’ records for a query, but at the same time, restrict the list of values that are returned from a ‘lookup’ table.
Is there a way to use ‘filter’ a CROSS JOIN without having to resort to using an in-line view?
This syntax works as expected (I get the desired results):
SELECT E.ID,
M.VALUE,
MT.ID, MT.NAME
FROM ENCOUNTER E
CROSS JOIN (
SELECT ID, NAME
FROM MEASUREMENT_TYPE
WHERE ID IN ('6941','6946')
) MT
LEFT OUTER JOIN MEASURE M ON E.ID=M.ENCOUNTER_ID
AND MT.ID=M.MEASURE_TYPE_ID
Unfortunately, if I use this approach, I need to use a Command object with Crystal Reports rather than its native ‘Visual Linking Expert’. Command objects irritate me.
Adding a filter to the WHERE clause results in an equal join, which is undesirable in this situation.
In this case you can put the filter in the WHERE clause because it’s a LEFT JOIN and you’re filtering the left side of the query.
If you were filtering the
Measuretable, the filter would have had to go in theLEFT JOIN‘s ON clause.An additional alternative is to
INNER JOINinstead ofCROSS JOINand use the filter there. This is because the ON clause doesn’t actually need to reference both tables…