1

I have a table which have two columns ADMI_ID and DIAG_ID.

|--------|--------|
|ADMI_ID |DIAG_ID |
|--------|--------|
|    1   | 46777  |
|    1   | 12457  |
|    2   | 12456  |
|    2   | 36835  |
|--------|--------|

I want to fetch this two separate DIAG_ID responding to the same ADMI_ID and store them in a variable in mysql stored procedure or insert them into a temporary table. Can you please help me ?

Zev Spitz
  • 13,950
  • 6
  • 64
  • 136
jack
  • 321
  • 1
  • 5
  • 20
  • Please provide some context - what do you want to do with this variable or temp table? – Zev Spitz Jul 26 '15 at 17:19
  • i want to combine it with other table such where I can match ADMI_ID of this table with other table and the resulting table should have something like----|ADMI_ID|Diag_ID_1|Diag_ID_2|.......|......| – jack Jul 26 '15 at 17:24
  • I want to merge the rows with same ADMI_ID and make a new table with three columns – jack Jul 26 '15 at 17:40
  • You mean a [pivot table](http://stackoverflow.com/q/7674786/111794)? MySQL doesn't have a built-in pivot operator. See [here](http://stratosprovatopoulos.com/web-development/mysql/pivot-table-with-dynamic-columns/). – Zev Spitz Jul 26 '15 at 17:45
  • Yes this is exactly what I am talking about ! Sorry didn't knew the terminology :( – jack Jul 26 '15 at 17:51
  • Can you help me write a query for this ? – jack Jul 26 '15 at 17:57
  • Did you read the links in my comment? – Zev Spitz Jul 26 '15 at 18:04
  • Yeah I read ur comment ! I want some help to make it working using query – jack Jul 26 '15 at 18:22

0 Answers0