Is this query irreducibly complex?
===

I have two MySQL database tables, described below. One table holds device information, and the other is a one-to-many log about each device.

    CREATE TABLE  `device` (
      `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
      `name` VARCHAR(255) NOT NULL
    );

    CREATE TABLE  `log` (
      `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
      `device_id` INT NOT NULL,
      `message` VARCHAR(255) NOT NULL,
      `when` DATETIME NOT NULL,
      INDEX (`device_id`)
    );

What I want to do is grab device information along with the latest log entry for each device in a single query (if possible). So far, what I have is the following:

    SELECT d.id, d.name, l.message
    FROM device AS d
    LEFT JOIN (
      SELECT l1.device_id, l1.message
      FROM log AS l1
      LEFT JOIN log AS l2 ON (l1.device_id = l2.device_id AND l1.when < l2.when)
      WHERE l2.device_id IS NULL
    ) AS l ON (d.id = l.device_id)
    WHERE d.active = 1
    GROUP BY d.id
    ORDER BY d.id ASC;

These queries are simplified reproductions of my actual setup, where my log table is over 100k rows (and there are actually several log tables I look at). The query does run, however very, very slowly (say, more than two minutes). I'm convinced that there is a more concise/elegant/"SQL" way to form this query to get the data I need, but I just haven't found it yet.

Is what I want to do even possible without the ugly sub-SELECT and self-JOIN? Can I get the job done with a different strategy? Or, is the very nature of the query something that is irreducibly complex?

Again, the application logic is such that I can "manually JOIN" the tables if this isn't going to work, but I feel like MySQL should be able to handle something like this without choking - but I'm admittedly green when it comes to this kind of complex set algebra.