Jump to content


Photo

Group By ... I Think


  • Please log in to reply
2 replies to this topic

#1 edlanter

edlanter
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 December 2003 - 06:29 PM

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!
James Lanter [br]The Criminal [br]the_criminal@fantasycriminal.com [br]www.fantasycriminal.com

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,015 posts

Posted 17 December 2003 - 07:21 PM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 edlanter

edlanter
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 December 2003 - 07:54 PM

Thanks!!!!!
James Lanter [br]The Criminal [br]the_criminal@fantasycriminal.com [br]www.fantasycriminal.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users