Search code examples
mysqlsqldenormalization

How to denormalize the data in MySQL?


My view data looks like this :

Data:

Country  qty   Amt    type
India     42   1000   1
India     32    59    2

I'm trying to denormalize the view data based on country, so that, two rows should be appeared as one row.

Required Form :

 Country  qty   Amt    type  qty    Amt    type
 India     42   1000   1      32    59     2

As I'm a newbie to MySQL, Can anyone please help me out regarding the same...


Solution

  • One method is a join:

    select t1.country, t1.qty, t1.amt, t1.type, t2.qty, t2.amt, t2.type
    from t t1 join
         t t2
         on t1.country = t2.country and t1.type = 1 and t2.type = 2;