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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GROUP BY only displaying 1 row within each group

Status
Not open for further replies.

dexthageek

IS-IT--Management
Mar 23, 2002
59
US
I have a database that consists of various sports schedules.

The part that is NOT working is GROUP BY. I am trying to group by a column titled "sport"

My current query:

Code:
SELECT * FROM `otis_sports` WHERE season = 'Fall' GROUP BY sport

This select statement only returns 1 row from each sport when in fact there are many more records.

I would also like to display a heading everytime the group changes.

I hope I havent confused anyone, if I have let me know and I will try to explain it again.

Thanks in Advance

Mike
 
It seems to me that you mixed up the concepts of 'group by' and 'order by'
hth
 
ok then is there a way for me to take the records in my database and display them in groups.

Here is an example of my database

ID SPORT SEASON Opponent DATE
1 Baseball Fall Jackson 10/15/2004
2 Football Fall Barnegat 11/15/2004
3 Football Fall Toms River 10/19/2004
4 Baseball Fall Howell 09/15/2004

I want to pull the data out and have the sports grouped together like this

Baseball
Howell 09/15/2004
Jackson 10/15/2004

Football
Toms River 10/19/2004
Barnegat 11/15/2004

At the moment I am acheiving this by created a Select statement and While statement for each sport. I was just curious if there was a way to pull the data out already grouped together.

Thanks again

Mike
 
order by" is what you want. That will get your list to be

ID SPORT SEASON Opponent DATE
1 Baseball Fall Jackson 10/15/2004
4 Baseball Fall Howell 09/15/2004
2 Football Fall Barnegat 11/15/2004
3 Football Fall Toms River 10/19/2004
 
I know ORDER BY will do that, but it wont seperate the results the way I want.

I will have to go back and create seperate while statements like i was before. I was just trying to find a way to group my results without alot of code.

Thanks

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top