I am working on a small app where I can import a list of products from an Excel file. These products are grouped by merchant and creation date, so the result in the database is like this:
MerchantID CreatedOn (Other product details...)
-----------------------------------------------------
1 3/10
1 3/10
1 2/10
2 3/10
2 3/10
2 2/10
3 3/10
3 3/10
3 2/10
I need to show the latest products on the homepage, but I want to ungroup the merchants like this (so it doesn’t show products of the same merchant together):
MerchantID CreatedOn (Other product details...)
-----------------------------------------------------
1 3/10
2 3/10
3 3/10
1 3/10
2 3/10
3 3/10
1 2/10
2 2/10
3 2/10
How could I “ungroup” this data? I don’t really need the whole query, just a tip to get me started, I’m really lost. Thank you so much.
It sounds like you just need to sort the data, so it isn’t sorted by MerchantID. Have a look at the OrderBy method, and try sorting by one of the product details, maybe the product name?
Once you’ve sorted by the product (or something else) then you can neaten it up to get the repeated 1, 2, 3 order by adding a second ordering, based on the MerchantID. Using ThenBy is also covered on that page.