0

I have been through many other post, related to my issue but did not find any solution, so please don't mention any other post.

I am using mysql. I am having two tables with the following structure

Items:

 ___________________________________________
| ITEM ID    |  TITLE  | PRICE  | QUANTITY |
|__________________________________________|
|112233      |ABCDE    |  45.00  |  7      |
|223344      |SFDFS    |  34.00  |  8      |    
|334455      |SDFSDF   |  30.00  |  8      |
|787878      |XVXCVX   |  23.45  |  6      |
|888888      |SFSDF    |  29.00  |  5      |
|            |         |         |         |
|____________|_________|_________|_________|

Itemspecifics:

 _______________________________________________
| ITEM ID    |  SPECIFIC NAME  | SPECIFIC VALUE |
|_______________________________________________|
|112233      | STYLE           |  standard      |
|112233      | BRAND           |  phonix        |    
|112233      | COLOR           |  white         |
|112233      | MFG             |  xyz           |
|112233      | YEAR            |  2021          |
|444444      | COLOR           |  black         |
|444444      | MFG             |  abc           |
|444444      | YEAR            |  2020          |
|____________|_________________|________________|

I want result something like following Result:

 ___________________________________________________________________________________
| ITEM ID    |  TITLE  | PRICE   | QUANTITY|  STYLE  |  BRAND  |COLOR | MFG |YEAR   |
|__________________________________________|_________|_________|______|_____|_______|
|112233      |ABCDE    |  45.00  |  7      | standard|  phonix |white | xyz |2021   |
|444444      |SFDFS    |  34.00  |  8      |         |         |black | abc |2020   |
|____________|_________|_________|_________|_________|_________|______|_____|_______|
  1. Specific Name and Specific Values in Itemsspecific table are dynamic and unknown.

Note: I can save data in other structure too if that is easier than the current structure.

Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

0

For dynamic, construct, then execute, the query. Here is a stored proc to do such:

http://mysql.rjweb.org/doc.php/pivot

Rick James
  • 135,179
  • 13
  • 127
  • 222