Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
HAVING clause check?
Message
 
 
To
08/05/2008 14:45:21
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01315930
Message ID:
01315933
Views:
16
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
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform