How to fetch data from a table which don't have a unique id We have a table that we used to store the points according to a section for a particular id, but the id values are not unique. 

  +---------------------+------+----------+
  | id                  | sec  |   points |
  +---------------------+------+----------+
  |                     | B    |        2 |
  |                     | S    |      183 |
  |                     | T    |     3225 |
  | ht01aa              | A    |    24227 |
  | ht01aa              | O    |      307 |
  | ht01aa              | U    |      466 |
  | ht01ab              | A    |    18640 |
  | ht01ab              | O    |      392 |
  | ht01ab              | U    |      501 |
  +---------------------+------+----------+

We need to change the table structure as mentioned below

  +--------+---------+---------+--------+---------+---------+--------+
  |    id  |  Sec A  |   Sec O |  Sec U |  Sec B  |   Sec S |  Sec T |
  +--------+---------+---------+--------+---------+---------+--------+
  |        |         |         |        |       2 |    183  |   3225 |
  | ht01aa |  24653  |    149  |   198  |         |         |        |
  | ht01ab |  19259  |    121  |   153  |         |         |        |
  +--------+---------+---------+--------+---------+---------+--------+


Here I need to combine all the points of a id based on the section. What's the best way to approach this? Thanks!
You want a pivot table (which isn't a inbuilt function in MySQL, but there are workarounds)

A rough example (I cant test this here):

select ID
   sum(if( sec = 'A', 1, 0)
       * points) as Sec A,
   sum(if( sec = 'O', 1, 0)
       * points) as Sec O,
   sum(if( sec = 'U', 1, 0)
       * points) as Sec U,
   sum(if( sec = 'B', 1, 0)
       * points) as Sec B,
   sum(if( sec = 'S', 1, 0)
       * points) as Sec S,
   sum(if( sec = 'T', 1, 0)
       * points) as Sec T,
   sum(if( sec = 'Y', 1, 0)
       * points) as Sec Y,
   sum(if( sec = 'Z', 1, 0)
       * points) as Sec Z
  from [schema].[table]
 group by id
;


NOTE: I've put section Y and Z as your additional sections as they don't appear in your example with what they are

If that doesn't work directly here's some external links with more detailed examples:


https://www.toadworld.com/platforms/mysql/w/wiki/6349.pivoting
http://modern-sql.com/use-case/pivot