|Data designs often require flexibility in numbers and names of data points per instance row: instead of saving all the data points belonging to a key value in a single row, you save each data point as a name-value pair in its own row. |
Thus given table user_class(user_id INT, class_id CHAR(20), class_value CHAR(20)) with these rows:
and you wish a resultset that links first names to last names for each ID...
the following query accomplishes the required pivot via an INNER SELF-JOIN: