Mysql Covert rows to columns -


i have table order numbers, first name, last name, question , answers. there 5 questions asked user, each answer question generates 1 row of data, produces 5 rows per user. need query returns order number, first name, last name , questions , answers converted columns, returning 1 row per user.

any appreciated

thanks, larry

seems want join table 5 times.

something like

select q1.first_name, q1.last_name, max(q1.question), max(q1.answer), max(q2.question), max(q2.answer),max(q3.question), max(q3.answer),... questions q1  join questions q2 on q1.first_name=q2.first_name , q1.last_name=q2.last_name  join questions q3 on q1.first_name=q3.first_name , q1.last_name=q3.last_name  q1.order_number = 1 , q2.order_number = 2 , q3.order_number = 3 ... group q1.first_name, q1.last_name 

using max collapse down rows unique first name/last name pairs.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -