Ask how to write a SQL statement, joint query

A table has fields
ID title
1 DDDDDDD
2 ccccccc
3 HHHHHHHH

There are fields
ID AID STATUS
120
211
321
430
510
in

B table.

ID in table A corresponds to AID in table B

I need to use a federated query to find all the data in table An and correspond to the latest table B records.

After working on

for a long time, I can only find the corresponding first record in Table B, not the latest record. For example, if the record with ID 1 in table An and the record with ID 2 in table B, what I need to find is the record with 5.
ask for advice!

Mar.24,2021

The idea of

@ jzoom is correct, but the field of the max function is not correct. Let me add:

select a.*, b.*
from a join (select aid, max(id) as max_id from b group by aid) b1 on a.id = b1.aid
       join b on b1.max_id = b.id

this is an obvious subquery
select a. ID. Aid from a join (select max (aid) as aid from b group by aid) b on a.id=b.aid
other fields please add


if the data in table B corresponds to only one piece of data in table A, it is OK to add a sort.

select a.*, b.* from b left join a on a.id = b.aid order by b.id DESC
Menu