Let's say I have two tables, one with schools and one with classes. Both tables have SchoolID so they can be matched. They look something like this:
TableSchools
SchoolID SchoolName
1 SchoolOne
2 SchoolTwo
3 SchoolThree
TableClasses
ClassID SchoolID ClassName
1 1 ClassOne
2 1 ClassTwo
3 2 ClassThree
4 2 ClassFour
5 2 ClassFive
6 3 ClassSix
7 3 ClassSeven
and I want my resultset to be like this
SchoolOne SchoolTwo SchoolThree
ClassOne ClassThree ClassSix
ClassTwo ClassFour ClassSeven
NULL ClassFive NULL
I've heared in TSQL I could use group by with rollup but it seems that's not possible or at least I don't understand how to use it from here.
rollupyou are looking for a "crosstab" aka "pivot".SchoolThree. As there are no data like this inTableSchools, I'm thinking: is this a typo or the names should be sequential, even not matching theSchoolNames inTableSchools?