I have been working on a database that holds order numbers and order information. Previously I used a report that provided an order ID and a unique item ID for each item ordered. The item ID was the primary key as it was a uniquely assigned value.
This meant that one order # could have multiple items within it, each item identified by a unique item ID.
Now our requirements have changed to become more real time, which means the report that provided the unique item ID's has not run. As such I will need to generate my own unique item id's, but only within the same order #.
Additional information for those who use Amazon's MWS:
Previously I was using the Reports API to generate _GET_AMAZON_FULFILLED_SHIPMENTS_DATA_ to provide our fulfillment data while a 3rd party integrations company pulled the _GET_FLAT_FILE_ORDER_REPORT_DATA_ report to handle our merchant fulfilled orders. We are now looking to make our merchant fulfilled orders real-time using the Orders API, which unfortunately does not provide the orderItemId that is provided by the _GET_FLAT_FILE_ORDER_REPORT_DATA_ file. The problem I need to solve is related to the absence of that field.
Some sample data to work with would be:
Order-ID Item-ID Item
222-2212 1 redShirt
222-2216 1 redShirt
222-2212 2 blueShirt
222-2212 3 greenShirt
222-2218 1 noShirt
I would like to be able to something like:
SELECT * from order_data WHERE Order-ID like '222-2212';
and have all 3 items returned. The problem I have is I have no idea how to provide a unique auto-incremented number based upon the count of the Order-ID. I also want to avoid using a standard auto-incremented value across all data as I could then end up with duplicate orders and would need to try and filter using DISTINCT.
Does anyone have any ideas, pointers or suggestions on how I may accomplish this? I do have the luxury of redesigning the entire database from scratch so I am open to suggestions.
--EDIT--
I am currently following up with Amazon to determine if the orderItemId returned by the orders API is randomly generated. I will post more details here when I find out.