Hi Sergey,
Ah yes...just looked at the results and realized that myself (now)...HAVING does not apply to all 3 - so looks like I have to do a subsequent query on the first results set if I want to cut down on typing. Thanks!
>No, only ORDER BY clause is applied to the whole result set. The HAVING clause is applied to each query in UNION. You can use derived table to apply additional conditions
>
>SELECT * FROM (
> SELECT ;
> File.* ;
> FROM File ;
> WHERE <unique conditions ;
> UNION SELECT ;
> File.* ;
> FROM File ;
> WHERE <more unique conditions ;
> UNION SELECT ;
> File.* ;
> FROM Files ;
> WHERE <more unique conditions ;
> ) dt1
>WHERE ;
> < 3 conditions common to the above)
>INTO CURSOR x
>
>
>>
>>Usually I use the "HAVING" clause in a SELECT statement to limit result rows in a situation where I am doing a GROUP BY at the same time (like a count using a GROUP BY).
>>
>>Is it legit - i.e. will I get correct results - to use filter conditions in the HAVING clause to avoid repeating a filter condition in a UNION? i.e. I have a 3 way UNION each of which has a couple of unique conditions but then all 3 of them have 3 more conditions. Instead of repeating these last 3 conditions 3 times, I thought maybe I could put them in as a "HAVING" as I think I remember reading that that works like a WHERE clause and is processed after the UNION is done. BTW, the unique conditions are complex enough I don't want to try to code a complicated set of conditions joined by two "OR"s. By doing it as a UNION, it is much more readable.
>>
>>Just want to confirm. Here is the example:
>>
>>
>>
>>SELECT ;
>> File.* ;
>> FROM File ;
>> WHERE <unique conditions> ;
>>UNION SELECT ;
>> File.* ;
>> FROM File ;
>> WHERE <more unique conditions> ;
>>UNION SELECT ;
>> File.* ;
>> FROM Files ;
>> WHERE <more unique conditions> ;
>>HAVING ;
>> < 3 conditions common to the above)
>>INTO CURSOR x
>>
>>
>>
>>Thanks,
>>Albert