Q:

Fastest way of doing a 1 to 1 left join on tables with a 1 to many relationship (MySQL)

I have two tables that have a 1 to many relationship, which I'm doing a 1:1 left join on. The query returns the correct results but it shows up in my slow query log (it takes up to 5s). Is there a better way to write this query?
select * from
tablea a left join tableb b 
  on a.tablea_id = b.tablea_id
  and b.tableb_id = (select max(tableb_id) from tableb b2 where b2.tablea_id = a.tablea_id)

i.e. I would like TableA left joined to the row in TableB with the largest tableb_id.
TableA
tablea_id
1
2

TableB
tableb_id, tablea_id, data
1, 1, x
2, 1, y

Expected Result
tablea_id, tableb_id, data
1, 2, y
2, null, null

TableA has an index on tablea_id and TableB has a composite index on tablea_id,tableb_id.
Explain Output
+----+--------------------+---------------+--------+-----------------+---------------+---------+----------------------+-------+-------------+
| id | select_type        | table         | type   | possible_keys   | key           | key_len | ref                  | rows  | Extra       |
+----+--------------------+---------------+--------+-----------------+---------------+---------+----------------------+-------+-------------+
|  1 | PRIMARY            | c             | index  | NULL            | department_id | 4       | NULL                 | 18966 | Using index |
|  1 | PRIMARY            | recent_cv_lut | eq_ref | PRIMARY,case_id | PRIMARY       | 4       | func                 |     1 |             |
|  2 | DEPENDENT SUBQUERY | cases_visits  | ref    | case_id         | case_id       | 4       | abcd_records_v2.c.id |     2 | Using index |
+----+--------------------+---------------+--------+-----------------+---------------+---------+----------------------+-------+-------------+

A:

Likely, that correlated subquery is getting executed for each row from tableb.
(Without the output from EXPLAIN, we're really just guessing as to whether appropriate indexes are available, and if MySQL is making use of them.)
It might be more efficient to use an inline view query, to get the maximum tableb_id value for each tablea_id in one shot, and then use a join operation. Something like this:
SELECT a.*
     , b.*
  FROM tablea a
  LEFT
  JOIN ( SELECT n.tablea_id
              , MAX(n.tableb_id) AS max_tableb_id
           FROM tableb n
          GROUP
             BY n.tablea_id
       ) m
    ON m.tablea_id = a.tablea_id
  LEFT
  JOIN tableb b
    ON b.tablea_id = m.tablea_id
   AND b.tableb_id = m.max_tableb_id

That's an alternative, but there's no guarantee that's going to be faster. It really depends, on a whole load of things that we don't have any information about. (Number of rows, cardinality, datatypes, available indexes, etc.)

EDIT
As an alternative, we could do the join between tablea and tableb in an inline view. This might improve performance. (Again, it really depends on a lot of things we don't have any information about.) 
SELECT m.tablea_id
     , m.foo
     , b.*
  FROM ( SELECT a.tablea_id
              , a.foo
              , MAX(n.tableb_id) AS max_tableb_id
           FROM tablea a
           LEFT
           JOIN tableb n ON n.tablea_id = a.tablea_id
          GROUP
             BY a.tablea_id
       ) m
  LEFT
  JOIN tableb b
    ON b.tablea_id = m.tablea_id
   AND b.tableb_id = m.max_tableb_id

