Ok I am trying to construct a query that will give me results a-z and group them within there primary category. Each result should give me about 30 or more listings per category. However with this query.
select teamName, CONCAT(UCASE(leagueType)) as league
from fmr_teamNames
group by leagueType
order by teamName asc
I will only get a single listing per category. Which I understand to a point cause I am using a group by condition.
When I reorder the query a little and remove the group by condition I get all my listings but they are in z-a. When the desired goal is categories a-z then the inner results per category a-z
select teamName, CONCAT(UCASE(leagueType)) as league
from fmr_teamNames
order by leagueType asc
This currently gives me a-z on the categories, and z-a on the results per. So I am a little confused as to how to better form this query for my results, without having to use some outside intervention like PHP to reorder everything.
I think you are mistaking the
concatfunction for thegroup_concatfunction in mysql. Concat will append two strings together, whilegroup_concatwill merge rows together.Your query also seemed to use a
group byon the aggregated column rather than the unique one you are trying to identify?Example: