Hello, I have this rather tricky design which baffles me.
The structures relevant to this question are as follows:
policy_list: policyID, policyname, region
policy_details: pdetailsID, pID (linked to policyID), pnotes, pdate
In essence, for every policy introduced, there're several revisions made in the long run. Policy_list tracks all the policies and their relevant information, while policy_details tracks the relevant revisions (as well as the details of the policy when it was first introduced).
In this query, I need to retrieve any policy revisions that take place within a user-provided date range, and also display the details of the policy when it was FIRST introduced. This 'first policy' need not be within the range.
I have tried a variety of query designs, and I narrowed it to a UNION SELECT, but because the report which utilises this query displays many other fields not in the same table, I will need to do a UNION SELECT of all the other fields as well. In this case, I will get an 'aggregate function' error when I try to do a Min(pdate) and Min(pdetailsID) to retrieve the 'first policy'.
Any ideas on how this can be done? I can't share my database files with all of you due to the confidentiality of this project, but I will definitely appreciate some input. Thanks a lot!
The structures relevant to this question are as follows:
policy_list: policyID, policyname, region
policy_details: pdetailsID, pID (linked to policyID), pnotes, pdate
In essence, for every policy introduced, there're several revisions made in the long run. Policy_list tracks all the policies and their relevant information, while policy_details tracks the relevant revisions (as well as the details of the policy when it was first introduced).
In this query, I need to retrieve any policy revisions that take place within a user-provided date range, and also display the details of the policy when it was FIRST introduced. This 'first policy' need not be within the range.
I have tried a variety of query designs, and I narrowed it to a UNION SELECT, but because the report which utilises this query displays many other fields not in the same table, I will need to do a UNION SELECT of all the other fields as well. In this case, I will get an 'aggregate function' error when I try to do a Min(pdate) and Min(pdetailsID) to retrieve the 'first policy'.
Any ideas on how this can be done? I can't share my database files with all of you due to the confidentiality of this project, but I will definitely appreciate some input. Thanks a lot!
