0

I have a customers table that houses contacts. Each contact is added as another row to that customer.

I want to create my query so that I can create columns for contact1, contact2, contact3 and so forth. What's the best way to do this?

My rows are dynamic and I have been looking into unpivot and pivot but I'm not sure how I would build that into my query as I have a few joins and other data in the query.

SQL Fiddle example

voloshin
  • 536
  • 7
  • 17

1 Answers1

0

Dynamic pivot query is what you need. See this: http://buysql.com/mysql/14-how-to-automate-pivot-tables.html

and this: SQL Server dynamic PIVOT query?

Community
  • 1
  • 1