SQLite Forum

SELECT question
Login
I have 2 tables from which I'm trying to extract data, but having some problems with the query.
<pre>
CREATE TABLE IF NOT EXISTS "docs" (
id integer not null primary key autoincrement,
authorid integer,
docid integer,
title text,
source text,
pubyear integer,
notes text,
author text,
filename text);

CREATE TABLE keywords (
id integer not null primary key autoincrement,
keyword text,
authorid integer,
docid integer);
</pre>

What I would like is to select the most recent 5 titles, along with ANY/ALL keywords attached to them.
The closest I can get is:
<pre>
select docs.id, title,author,source,docs.authorid,docs.docid,keyword,keywords.authorid,keywords.docid from docs,keywords where docs.authorid=keywords.authorid and docs.docid=keywords.docid  order by docs.id desc limit 5;
49|Redeeming Charles Babbage's Mechanical Computer|Swade,Doron D.|Scientific American 1993-02|1009|1|Computer Technology|1009|1
49|Redeeming Charles Babbage's Mechanical Computer|Swade,Doron D.|Scientific American 1993-02|1009|1|Difference Engine|1009|1
49|Redeeming Charles Babbage's Mechanical Computer|Swade,Doron D.|Scientific American 1993-02|1009|1|Engineering|1009|1
48|A Partly True Story|Stewart,Ian|Scientific American 1993-02|1008|1|Fuzzy Logic|1008|1
48|A Partly True Story|Stewart,Ian|Scientific American 1993-02|1008|1|Mathematics|1008|1
</pre>
However, the 'limit by' seems applied to the title only, not the final result as above. I don't know ahead of time how many keywords each title may have - most are > 1. 

In any case I would like the most recent 5 titles plus their attached keywords. 

I'm sure this can be done in a single SQL query but so far it has escaped me. Any advice / suggestions greatly appreciated.