We have a business requirement to keep a repository of clients up to date in Salesforce, to that end it's been decided that we should implement a small rest API returning JSON that is able to be cached and paged that will be queried once a day-ish.
The current plan is to call a stored procedure inside SQL Server, to call upon a custom view.
However returning all the results would be very inefficient to both serve as JSON, page through, etc.
Luckily all the relevant rows in the database, have a LastUpdated timestamp, Unluckily it's fairly well normalized, so now I find myself in the position of merging upwards of 15 tables worth of LastUpdated dates in a max-like function, which appears fairly complex to do in SQL in a null safe manner.
I probably don't actually need the LastUpdated data in Salesforce, which makes me wonder, would it be better to Take the max of 15 LastModified columns in various nested queries, or compare them all to the input date in many different where clauses, and somehow join them all back to the root object (student in this example).
e.g. for a simple example of 3 tables (ignoring the fact my real world query has several sub queries already that I barely understand, (In reality students have 1 or more guardians, guardians have 1 or more phone numbers of varying types)
Student
-------------------------------------------------------------------------
StudentID | Student | SchoolID | GuardianID | LastModified
Guardian
-------------------------------------------------------------------------
GuardianID | Name | Phone | LastModified
School
-------------------------------------------------------------------------
SchoolID | Name | Phone | LastModified
To end up with a view that would export
View
--------------------------------------------------------------------------------------------------------------------
StudentID | Student | SchoolName | SchoolPhone | GuardianName | GuardianPhone | LastModified
Where either the LastModified is the latest of all 3 tables, OR all entries in the view are somehow the most recent changes, perhaps using rowversions?