I'm just starting out in SQL so as always, apologizes for the notive question. I'm using SQL it for reporting purposes. I'm not trying to write data. I did not set up/nor can I modify any tables in my system.
The problem I can not seem to overcome this past weekend while googling and testing things is I have a functioning query that gives me 1 row of data across various tables per GUID [Main_ID
]. I need to pull some data from another table that shares the same [Main ID
] and has various but constant secondary IDs [Attribute_ID
].
To go into more detail about the table, Attribute_IDs
('Att_1'
, 'Att_2'
,...) are constant throughout the system regardless of the Main_ID
. And each Attribute_ID
always correlates to the same column ('Att_1' = archar255
, 'Att_2' = archarMAX
). There is only 1 column of data per Attribute ID. The values in the 3 rightmost columns are strings that vary.
Table - Value_Table
+-----------+--------------+----------------+----------------+-------------+
| Main_ID | Attribute_ID | archar255 | archarMAX | LookupValue |
| GUID_ID_1 | Att_1 | | blah blah | |
| GUID_ID_1 | Att_2 | 255 value test | | |
| GUID_ID_1 | Att_3 | | | LV |
| GUID_ID_1 | Att_4 | | MAX | |
| GUID_ID_1 | Att_5 | | something else | |
+-----------+--------------+----------------+----------------+-------------+
Expected Output -
+-----------+-----------+----------------+-------+-------+
| Main_ID | Att_1 | Att_2 | Att_3 | Att_4 |
| GUID_ID_1 | blah blah | 255 value test | LV | MAX |
+-----------+-----------+----------------+-------+-------+
If anyone is willing to help me out, or just simply point me in the right direction, I would be most appreciative.
I have tried using WHERE
statements and CASE
but it can only point to 1 of the 5 rows that actually exist.