Try a sub select that returns the count...

SELECT 

t.Primary_Key,
h.Name,
(Select Count(tt.Name) as Count_Name
FROM myTable tt
where tt.Name = t.Name
)
FROM myTable tt

It's fast & returns all nesc data from the db.

David Schwartz

-----Original Message-----
From: Keith [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 1:45 PM
To: Taglibs
Subject: Conditional Loop

Here's a generic scenario similar to my situation:

A database with two columns, one being an auto-sequence number for the
primary key, the
other listing names.

1   Bob
2   Bob
3   Jim
4   John
5   Jim
6   Bob
7   John
8   John
9   Jim
10  Bob

Ok, I query the database to return both columns, since I need all the stored
data. But I
also want to get the number of each unique name in the 'names' column (how
many Jim's,
how many Bob's, and how many John's). I know I could do a separate query
looking for a
count() on each unique name, but that's not realistic with the amount of
data I'm dealing
with (actually tried doing it and nearly killed the poor DB server).

Normally, I'd do this with a 'while' conditional loop and a counter
incrementing while
the 'name' column contains a specific value, but I don't see that
functionality in JSTL.
I had asked generally before if JSTL had any 'while' loop capability, but
got no
response. So, I figured I'd give an example of what I'm trying to do and
maybe someone
could help.

Thanks!

Keith

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to