It sounds like you're just trying to have all the different values. What for? To display goals? This is an application, not a server. You could just ask three queries:
SELECT DISTINCT [Food Group] FROM atable; SELECT DISTINCT Name FROM atable; SELECT DISTINCT [Caloric Value] FROM atable;
and display their results accordingly.
But if you insist that they all be in the same table, you can try the following:
WITH atable ([Food Group], Name, [Caloric Value]) AS ( SELECT 'Vegetables', 'Broccoli', 100 UNION ALL SELECT 'Vegetables', 'Carrots', 80 UNION ALL SELECT 'Fruits', 'Apples', 120 UNION ALL SELECT 'Fruits', 'Bananas', 120 UNION ALL SELECT 'Fruits', 'Oranges', 90 ), atable_numbered AS ( SELECT [Food Group], Name, [Caloric Value], fg_rank = DENSE_RANK() OVER (ORDER BY [Food Group]), n_rank = DENSE_RANK() OVER (ORDER BY Name), cv_rank = DENSE_RANK() OVER (ORDER BY [Caloric Value]) FROM atable ) SELECT fg.[Food Group], n.Name, cv.[Caloric Value] FROM ( SELECT fg_rank FROM atable_numbered UNION SELECT n_rank FROM atable_numbered UNION SELECT cv_rank FROM atable_numbered ) r (rank) LEFT JOIN ( SELECT DISTINCT [Food Group], fg_rank FROM atable_numbered) fg ON r.rank = fg.fg_rank LEFT JOIN ( SELECT DISTINCT Name, n_rank FROM atable_numbered) n ON r.rank = n.n_rank LEFT JOIN ( SELECT DISTINCT [Caloric Value], cv_rank FROM atable_numbered) cv ON r.rank = cv.cv_rank ORDER BY r.rank
source share