Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy SQL question 2

Status
Not open for further replies.

eladi

Programmer
Sep 4, 2001
80
AU
Hi all,

This must be easy to achieve. I searched the forum already, but didn't find a post that really helped me out.

I have a db which pictures from my travels. I have a page where I say something short about a continent and then want to desplay from which countries there are pictures available and how many. The first part is easy:

<cfquery name=&quot;africa&quot; datasource=&quot;travels&quot;>
select distinct country from pictureDB where continent = 'Africa' order by country
</cfquery>

<cfoutput query=&quot;africa&quot;>
<li class=&quot;text&quot;>#country#</li>
</cfoutput>

But how do I how do I display how many entries there are of a certain country. It must be something with count(). Can't find the correct solution though.

Adrian
 
instead of your distinct query, try this

[tt]select country, count(*) as pics
from pictureDB
where continent = 'Africa'
group by country
order by count(*) desc[/tt]

rudy
 
Buuuuuut... wouldn't pics then return the total number of entries, rather than the number of entries in each group (country)?? Hope it helps,
-Carl
 

no, because the query contains a GROUP BY


try it :)
 
Coolness!

That earns a star, and it wasn't even my question! [wink] Hope it helps,
-Carl
 
hei rudy,
excellent! works perfectly, tnx a lot! the star is yours!
adrian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top