BeachSandGuy
Programmer
Hi, I have a data table that has elements like the following:
UniqueRecord | Phone | Type | Status |
101 | 5551111 | Tech | Closed |
102 | 5552222 | CS | Closed |
103 | 5553333 | Support | Pended |
104 | 5551111 | CS | Closed |
105 | 5551111 | Support | Open |
106 | 5553333 | CS | Open |
I want to grab the latest data by unique phone number, the latest having the largest UniqueRecord.
The results should be:
UniqueRecord | Phone | Type | Status |
102 | 5552222 | CS | Closed |
105 | 5551111 | Support | Open |
106 | 5553333 | CS | Open |
So I wrote a query like this:
However I am getting the following:
UniqueRecord | Phone | Type | Status |
102 | 5552222 | CS | Closed |
105 | 5551111 | Tech | Open |
106 | 5553333 | Support | Pended |
I'm sure its due to the way I am using the Max function, which works on the right UniqueRecord and Phone, but the other fields which I just want to bring over, I can't use "Last" like I have done in the past in Access. Max seems to look for the alphabetically largest value and not the value related to the unique record/phone. How can I write this to get the results I am looking for? I've been looking and just can't seem to figure it out. Thanks!
BeachSandGuy
UniqueRecord | Phone | Type | Status |
101 | 5551111 | Tech | Closed |
102 | 5552222 | CS | Closed |
103 | 5553333 | Support | Pended |
104 | 5551111 | CS | Closed |
105 | 5551111 | Support | Open |
106 | 5553333 | CS | Open |
I want to grab the latest data by unique phone number, the latest having the largest UniqueRecord.
The results should be:
UniqueRecord | Phone | Type | Status |
102 | 5552222 | CS | Closed |
105 | 5551111 | Support | Open |
106 | 5553333 | CS | Open |
So I wrote a query like this:
Code:
Select Max(UniqueRecord), Phone, Max(Type), Max(Status) From Table Group By Phone
However I am getting the following:
UniqueRecord | Phone | Type | Status |
102 | 5552222 | CS | Closed |
105 | 5551111 | Tech | Open |
106 | 5553333 | Support | Pended |
I'm sure its due to the way I am using the Max function, which works on the right UniqueRecord and Phone, but the other fields which I just want to bring over, I can't use "Last" like I have done in the past in Access. Max seems to look for the alphabetically largest value and not the value related to the unique record/phone. How can I write this to get the results I am looking for? I've been looking and just can't seem to figure it out. Thanks!
BeachSandGuy