Merge or delete semi-duplicates in an array - duplicates

I need to either merge or delete semi-duplicates in a Dataverse table. I looked into duplicate detection there, but I couldn't figure it out. I want to point out that that might be the solution to this and might be easier than what I'm asking for here. If I could keep the duplicates from writing to the table in the first place, that would be better.
In Power Automate, I create an array out of the aforementioned Dataverse table. Particularly, I'm looking at objects with duplicate Order Number values. Below is an example portion of the array. These three objects have the same Order Number but different Schedule Date.
I will have this array sorted by the Schedule Date, because I want the Schedule Date to be the earliest. Using Power Automate, how could I merge these records or remove all but the first one?

Related

Merging several rows based on conditions in MySQL

I have a large database containing informatiom about orders. Each order has a unique number, a tripnumber it is assigned to and a location number.
It sometimes happens that multiple orders are delivered to the same location, during the same trip. I want to merge these entries into one, as they are skewing my analysis results.
I want to iterate over the entire table, checking in every trip whether there are orders that have the same location number. If so, I want to update the rows in MySQL to either add together the values in the columns of that row or take the maximum of the two.
Is this possible in just MySQL?
I am fairly new to using MySQL (and coding in general) so I'm not sure how to write anything that iterates in it.

Design - Microsoft Access - Unique "Serial" Number

I am looking for some design techniques to achieve the following:
A 3-part serial number that is generated upon record entry. Format Example: 25-001-14
The number is used to track yearly records from various locations.
The first part states the location the record is associated with, this would be a user input during record creation.
The second part is the record number, I would like for this to be automatically generated, but needs to be sequential and separate for each location and needs to reset each year.
The third part is the two digit number for the year the record was created in. I would like this to be automatically generated if possible. Note: I am currently not concerned with when this cycles back around and I face redundant data issues.
I'm thinking I would like records to be stored in multiple tables that are separated by location, if this would help things!
Any ideas would be greatly welcomed.
I think I would use 3 key fields - one field each for location, record and year. The location and year fields would be created when you get the input to create new records. I would set up a query to find the last record number used by location and year and use that query to assign the new record number when you create a new record. The concatenation of the 3 fields would be the key you described.
With a key field for location, separate tables are not necessary unless that's useful for other reasons. I would probably use just one table - you can always filter the records by location anytime you need to.

Storing Invoices in MySQL

I wanted to get some advice on how to go about storing invoice data in a mysql database.
My first understanding would be to have two tables..
Invoices & Invoice_rows..
Invoices would hold FK to Client ID, invoice number, invoice date, paid or unpaid flag
Invoice_rows would hold all the items to invoice, FK to invoices, description, price, tax
Only thing is after the invoice is created it might need to be updated.. spelling mistake, extra item needed to be added etc. So for this is i will first need to query to get all of the rows, then I will need to execute multiple updates to all the rows every time a change is made.
Would storing all the rows as JSON in a text field for each individual invoice in the single invoices table work well or cause more of a problem? the fact that all rows will need to be updated regardless if there was only a change to one row upon save makes no difference just converting it to json and replacing the text field with the new JSON surely? The JSON wouldn't need to be searchable either as it's the client that will be searched and will list all of their invoices based upon their ID.
Any recommendation to make this efficient and easy to work with is most appreciated!
Just keep track of the changes in the front end and call your AJAX method when they're done. The method should take the invoice number and any updated rows including the PKs.
Do NOT store JSON in the database. That would be a truly awful thing. JSON is just a useful mechanism for transit and your choice of UI. It is not your data but a temporary transformation of it.

MySQL virtual fields for duplicate results

I apologize in advance that I don't know the terminology of the tools I'm trying to use.
I have a table of events with a startdate field (among others) and a related repeats table with a reference to the event id. The repeats table stores the days of the week on which the event repeats and whether it's monthly, weekly, etc. What I'm hoping to do is duplicate the repeating events within the SQL query so my final result will have the the same event in different places when ordered on start date, so I can limit the results for proper pagination.
I'm looking at creating virtual tables and cloning tables documentation, but I'm having trouble applying the examples to my situation.
Update:
Hopefully I can elaborate on this.
The basics of what I have now is SELECT * FROM 'events' WHERE 'start_date' >= TODAY() ORDER BY 'start_date LIMIT 20 which gets me every event from today on, but I'm paginating the results so only 20 are displayed at a time.
What I would like to do is create a temporary 'virtual' table with the events which have an associated repeat entry, on which I will change the start_date based on the repeat information. So if it's a weekly repeat, this second table would be filled with identical events except that each start_date would be 7 days from the last. Then I could do a join on these two tables, limit those results to the 20 pagination limit I want, and have a query result with the events in the correct place and easy to perform pagination on.
I understand that creating a function in mySQL might be on the right track as I imagine I would have to loop through some information for adding to dates. I only know the level of SQL one picks up by writing in PHP, so functions are a bit out of my scope, though it doesn't seem that it'll be too hard to pick up with a little reading. I'm more confused about how I would create a fake table, add entries to it in a loop and then use a join on it to merge it with the first query.
I'm also beginning to wonder about the overhead for doing this in mySQL and, should I be successful in getting this to work, how I might cache these results, though it's only an afterthought right now.
Thanks to those who are trying to help me, I'm having trouble getting this question into words for some reason.

Grouping in SSIS

So, I have a bunch of data that I'm trying to import using SSIS. The problem I'm having is that some of the data is outdated. So I want to only import the most recent data. I have a key that indicates which set of data each row belongs and I only want to import the most row per key.
What is the best way to do this in SSIS?
My only thought would be to use two sort transform. The first would sort by date. The second would sort by my key, and eliminate duplicate rows. This would only work if the sort was guaranteed to maintain the previous order. Does anyone know if this holds true? Or does the second sort completely eliminate order the first sort put into place?
I don't think you can rely on the sort order. You can sort by multiple keys in a single sort - perhaps sending it through a script task at that point to do the filtering by simply comparing it to the previous row.
I usually split (multicast) my dataset : one to aggregate the value I want to keep, the other one is used to merge with the first dataset.
For example, I have an history of position by employee (Employee, Date, Position)
I split my dataset to retrieve the last history date by employee (aggregate employee and max date) and I sort it by employee => 1.Employee + 1.last_date
I merge my 2 dataset => 1.Employee = 2.Employee AND 1.last_date = 2.date