EasyCFM.COM ColdFusion Forums / Coding Help! / Union question

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Union question

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

riogrande
02-14-2008 @ 2:24 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 509
Joined: Mar 2003

This works fine joining two queueries together the first one where country_count is more than 5 and the second where country_count is less than 5. How do I add an "alias" so I can give a name to the results of all the second results?  

<cfquery name="q_countries" datasource="mydsource">
SELECT UCASE(country) AS Country, COUNT(*) AS country_count, Visit,
IFNULL(country='Not Defined', country)
FROM clientinfo
WHERE month(visit) = #url.monthnowis#
GROUP BY country  
HAVING country_count > 5
UNION
SELECT country, COUNT(*) AS country_count, Visit,
IFNULL(country='Not Defined', country)
FROM clientinfo
WHERE month(visit) = #url.monthnowis#
GROUP BY country  
HAVING country_count < 5
ORDER BY country_count
</cfquery>

Scarecrow
02-14-2008 @ 5:45 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Oct 2004

First question is why are you seperating this into 2 queries ?

Next is I don't understand
so I can give a name to the results of all the second results

The union results in only one (1) result set not two (2)

Ken

www.krcaldwell.com

This message was edited by Scarecrow on 2-14-08 @ 5:45 PM

Lossed
02-15-2008 @ 4:42 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

3rd: what ever happened to posting DB questions in the DB forum as discussed recently?

4th: did you read this ifNull() answer and the link therein?

Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

Sponsored By...
iOpenSoft, LLC is a Houston, Texas Advanced Technology Studio Specializing in Web Design, Web Development, iPhone App Development and Android App Development.