Peter Cooney
2012-02-24 17:34:58 UTC
Greetings,
I'm looking for some assistance with writing a SQL query...
I have three tables which can be simplified as follows:
ServiceJob: primaryKey | modifiedOn | modifiedBy | modifiedById
| ... ... ...
Task: primaryKey | regardingId | modifiedOn | modifiedBy |
modifiedById
Note: primaryKey | regardingId | modifiedOn | modifiedBy |
modifiedById
In all three tables, primaryKey, regardingId & modifiedById are GUIDs,
modifiedOn is a datetime, modifiedBy is a nvarchar. The regardingId
columns in Taske & Note relate to a primaryKey in the ServiceJob
table.
The query I'm trying to produce needs to return the MAX(modifiedOn),
modifiedBy & modifiedById across all three tables for each row in the
ServiceJob table (along with various other columns from the ServiceJob
table). Performance optimisation, while desirable, is not critical as
this will primarily be used for a report as opposed to a real-time
application, however this may change in the future. To this end, I
would prefer to be able to build this in a view (as such, temporary
tables are out)
I hope I've explained things sufficiently, if further details are
needed, please let me know.
Many thanks in advance!
I'm looking for some assistance with writing a SQL query...
I have three tables which can be simplified as follows:
ServiceJob: primaryKey | modifiedOn | modifiedBy | modifiedById
| ... ... ...
Task: primaryKey | regardingId | modifiedOn | modifiedBy |
modifiedById
Note: primaryKey | regardingId | modifiedOn | modifiedBy |
modifiedById
In all three tables, primaryKey, regardingId & modifiedById are GUIDs,
modifiedOn is a datetime, modifiedBy is a nvarchar. The regardingId
columns in Taske & Note relate to a primaryKey in the ServiceJob
table.
The query I'm trying to produce needs to return the MAX(modifiedOn),
modifiedBy & modifiedById across all three tables for each row in the
ServiceJob table (along with various other columns from the ServiceJob
table). Performance optimisation, while desirable, is not critical as
this will primarily be used for a report as opposed to a real-time
application, however this may change in the future. To this end, I
would prefer to be able to build this in a view (as such, temporary
tables are out)
I hope I've explained things sufficiently, if further details are
needed, please let me know.
Many thanks in advance!