In SQLite, tables x and y are defined as follows:
CREATE TABLE x (
    x_pk INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
);
CREATE TABLE y (
    y_pk INTEGER PRIMARY KEY AUTOINCREMENT,
    x_fk INTEGER,
    rating REAL,
    date default current_timestamp,
    FOREIGN KEY (x_fk) REFERENCES x (x_pk)
);
Table y provides a log of past ratings, but should also provide the latest rating of each item in table x. I can get the latest rating of a single item (e.g. x_fk=8) using: SELECT * FROM y WHERE x_fk=8 ORDER BY date LIMIT 1;, but how can I select the single most recent rows for every distinct x_fk in table y?
 
    