I have this unstructured table where (1) itemID has multiple receptCodes associated with it. What I need to do is to display each receptCode associated with a distinct orderID in one row. Current table structure is similar to this:
itemID | receptString
=============================
itemID1 | receptString1
itemID1 | receptString2
itemID1 | receptString3
itemID1 | receptString4
itemID2 | receptString5
itemID2 | receptString6
Desired output:
itemID | receptString | receptString | receptString | receptString |
============================================================================
itemID1 | receptString1 | receptString2 | receptString3 | receptString4 |
itemID2 | receptString5 | receptString6 |
What would be the correct way to go about writing the query for this? I tried using multiple CASE statements and GROUP BY but I am struggling with the logic on this one. There can only be a MAX of (5) receptStrings per orderID but can vary between 1 – 5 receptStrings. The receptStrings can be a combination of characters, symbols, and numbers. I’m not concerned if NULLs show up. This is only part of what I need but is what I am struggling with. I'm testing this in both PostgreSQL and Oracle SQL.
* UPDATE *
Thank you everyone for your suggestions. The problem ended up being a little more significant than we originally anticipated (the example table I provided was a small piece of a very large pie) so we decided to take a different approach. Thanks again.