Thanks for your help!
Sorry for just used an improper example for my question ;-) . That example dosen't have any logical meanings. I'd just like to know how to make the UNION occurs before the INTERSECT operation. Your advice is to import an extra SELECT clause on the UNION results. Will this bring much negative effects to runtime
efficiency when I have lot of UNION results to INTERSECT?

Best regards,
Nan Ye

Igor Tandetnik wrote:
Nan Ye <nan.ye-nwzjn9QkdiXhIMfW0+CuwW/[EMAIL PROTECTED]> wrote:
   If I used UNION and INTERSECT in compound SELECTs, how to change
the default priority?
   For example,
      SELECT id FROM sample_a WHERE value > 3.0 INTERSECT SELECT id
FROM sample_b WHERE value < 4.0 UNION SELECT id FROM sample_b WHERE
value > 7.0;
   The default results is that it makes the intersection firstly and
then makes the union. If I want the union occurs before the
intersection, what should I do?

Why, put the UNION first, of course:

SELECT id FROM sample_b WHERE value < 4.0
UNION
SELECT id FROM sample_b WHERE value > 7.0
INTERSECT
SELECT id FROM sample_a WHERE value > 3.0;

Or, if you want explicit grouping, you can do this:

SELECT id FROM sample_a WHERE value > 3.0
INTERSECT
select * from (
   SELECT id FROM sample_b WHERE value < 4.0
   UNION
   SELECT id FROM sample_b WHERE value > 7.0
);

In this particular case, you don't even need the UNION:

SELECT id FROM sample_a WHERE value > 3.0
INTERSECT
SELECT id FROM sample_b WHERE value < 4.0 OR value > 7.0;

Igor Tandetnik


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------




-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to