Jump to content

Archived

This topic is now archived and is closed to further replies.

edlanter

Group By ... I Think

Recommended Posts

Hi. Here is what I would like a querry to display ....

 

State County

Viginia Roanoke

Salem

Blacksburg

 

Vermont Norwich

Veronie

 

In english, I would like to create a querry that only prints the State the

first time it is selected followed by the county for each line the State is the same as the previous one. In the example, the state changed from Virginia to Vermont so it printed Vermont. (the example is supossed to be two columns)

 

Something is telling me this is a Group By command, but I honestly can\'t remember so any feedback would be great.

 

Thanks!

Share this post


Link to post
Share on other sites

Nope, not a \'GROUP BY\' in this instance, that\'s for totals, averages etc.

 

You need to \"select state, county from tablename order by state, county\"

 

When you process the records, test for a change of \'state\' and only output the state value when not equal to the previous one. Always output the county value.

 

hth

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.