I’m left joining 2 tables (table1 and table2).
The 1st table contains unique globalcid of each record, 2nd table contains multiple occurrences of the same globalcid. Note: globalcid is the reference field of table2 to table1.
table1
globalcid / itemdesc
1 / item 1
2 / item 2
3 / item 3
4 / item 4
5 / item 5
table2
globalcid / recordcid
1 / 1
1 / 2
2 / 1
3 / 1
3 / 2
3 / 3
5 / 1
I want a query to return only the records from [table1] with record in [table2] GROUP BY table2.globalcid but will return last record of each globalcid
In the example above it should return
globalcid / itemdesc / table2.globalcid
1 / item 1 / 2
2 / item 2 / 1
3 / item 3 / 3
5 / item 5 / 1
If you’re only concerned about the
recordcidand do not need any other columns from that table, then this should be fine. However, if there are other columns in the table like such:…then the
MAX()value will not line up with its corresponding row data inothercolumn, and instead you must wrap the selection of the max in a subselect like so:Resulting in: