mysql> desc logs ;
+----------------+---------------+------+-----+---------+-------+
| Field          | Type          | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| USERNAME       | varchar(8)    |      | PRI |         |       |
| TITLE          | varchar(40)   | YES  |     | NULL    |       |
| FILEPATH       | varchar(35)   | YES  |     | NULL    |       |
| ENTRIESPERPAGE | int(2)        | YES  |     | NULL    |       |
| BACKTEXT       | varchar(30)   | YES  |     | NULL    |       |
| FORWARDTEXT    | varchar(30)   | YES  |     | NULL    |       |


mysql> desc log_entries;
+----------+---------------+------+-----+---------+----------------+
| Field    | Type          | Null | Key | Default | Extra          |
+----------+---------------+------+-----+---------+----------------+
| USERNAME | varchar(8)    |      | MUL |         |                |
| TITLE    | varchar(60)   | YES  |     | NULL    |                |
| date     | timestamp(14) | YES  |     | NULL    |                |
| entry_id | int(11)       |      | PRI | 0       | auto_increment |
+----------+---------------+------+-----+---------+----------------+


ok i have the above two tables....  the "username" field in both should be of the same 
set of valid usernames, but in logs username is unique (one row per user) and in 
log_entries it is not (one row per entry that each user has posted).  the "title" 
fields in both tables are never the same.

the query that i want to do is to select the 5 most recent unique usernames from 
log_entries (using distinct and date desc) and then join that to logs (using the fact 
that every username in log_entries has an entry in logs somewhere) to get their 
overall log title.

i have tried all sorts of variations but cant seem to get them to come out in the 
right order in one sql statement.

if anyone has time to investigate this further, i can send you some 30 rows of test 
data...

many thanks,

-will w.

Reply via email to