PDA

View Full Version : looking for sql command


gcapp
12-02-2002, 04:34 PM
Can someone tell me what command to use in an sql statement if I have a table that has a field that I want to group records on.

My example is a have a table with a field called District and there are records that have District 1, District 2, etc. in them. I'd like to group on District 1 and have the names of the people list under that group and then have it ordered by District 1, 2, 3, etc.

My table records are like this:

DISTRICT NAME PARTY
District 1 John Doe Republican
District 1 Joe Shmoe Democrat
District 4 John Deer Republican

I'd like the results to look like:

District 1
John Doe
Joe Shmoe

District 4
John Deer

I tried this sql statement, but it doesn't work:
"SELECT * FROM Legislature GROUP ON District ORDER BY District ASC;"

Can someone help??

Thanks,
Gary

whammy
12-03-2002, 12:47 AM
Hmm, I'd first do a SQL query to get the distinct DISTRICTs and stick them in a string with a delimiter (like "|") and (after removing the last "|" with a Left() statement) split that string into an array...

Then I'd loop through the array (i.e. For i = 0 to UBound(districtarray)) and do a sql query for each member of the district that way... if I read what you're trying to do correctly.

Hope this helps. :)