I have two MySQL tables and would like to select the highest value results from table2 and append these to table 1.
Table 1 contains ID, MSISDN (14 digit number)
Table 2 contains ID, MSISDN, field2, date
I want to return a list of all MSISDNs in table 1 and also the result for table2.field2 and table2.date where table2.date is the maximum value for the matching MSISDN.
How would I do this? I know I need to use MAX but I’m not sure how to construct the subquery to add the correct result for table2.field.
Typically, you would do this by
Note that if there are two identical (MSISDN, date) records, they will both be returned.
SQL Server