I have a table, T1, with an ID and some other fields.
I have another table, T2, with an ID (which matches the ID in the 1st table), a sort_order and a value. The ID and the order are a composite primary key.
For my output I need to have a single row with ID, then value1, value2, value3 ... value*n* (in practice I'll be stopping at 12)
I can obviously do this by left joining T2 onto T1 multiple times:
SELECT T1.ID, T1.[Other fields], T2_1.Value AS Value1, T2_2.Value AS Value2 ...
FROM T1
LEFT JOIN T2 AS T2_1 ON T1.ID = T2_1.ID AND 1 = T2_1.Sort_Order
LEFT JOIN T2 AS T2_2 ON T1.ID = T2_2.ID AND 2 = T2_1.Sort_Order
...
But I was wondering if there was a better way? Or at least one that looked neater!
SQL version is 2008.
Thanks.