0

How to populate selective values from one column to another column based on condition on second column? I have data in the following format

**name         role_id** 
-------------------------
jack           6 
jill           8  
humpty         9 
dumpty         9  

Looking for Output

**'6'          '8'       '9'** 
-------------------------------
jack        jill      humpty
NULL        NULL      dumpty 

so how can I segregate data based on role_id?

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Are there only three `role_id` values in your table? – Tim Biegeleisen Apr 12 '16 at 10:42
  • if there are more than three `role_id` values, better use some server side script to create such output. – mitkosoft Apr 12 '16 at 10:44
  • This is called pivot table or cross tabulated (crosstab) query. The linked topic contains mysql implementation for both static (columns are known in advance) and dynamic (columns are determined on the fly) pivot. – Shadow Apr 12 '16 at 11:13

0 Answers0