0

I have a table with id, number, lang, phrase

For each number are multiple entries like

     1, 01, de, Hallo
     2, 01, en, Hello
     3, 01, fr, Salut,
     4, 02, de, Guten Tag
     5, 02, en, Good Day
     ..

The number of languages is fix

How can I create a view with the data arranged like

    id, de, en, fr 
    1, Hallo, Hello, Salut
    2, Guten Tag, Good Day, ''
user9527
  • 28
  • 1
  • 7
  • possible duplicate of [MYSQL - Rows to Columns](http://stackoverflow.com/questions/1241178/mysql-rows-to-columns) – Pred Jan 19 '15 at 13:11
  • possible duplicate of [MySQL pivot table](http://stackoverflow.com/questions/7674786/mysql-pivot-table) – Marcus Adams Jan 19 '15 at 13:44

1 Answers1

1
select number,
       max(case when lang = 'de' then phrase end) as de,
       max(case when lang = 'en' then phrase end) as en,
       max(case when lang = 'fr' then phrase end) as fr
from your_table
group by number
juergen d
  • 201,996
  • 37
  • 293
  • 362