Help with a JOIN statement
| From: | Michael Robbins | Date: | Fri, 19 Apr 2002 20:54:37 +0000 |
| Subject: | Help with a JOIN statement | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-18685@lists.php.net to get a copy of this message | ||
I have 2 tables, 'users' and 'files' (defined below)
Can I construct a single SELECT statement so that it will return ONLY
users that have files and ONLY the last file that the user has? So it
would return 1 row per user containing their most recent file.
users
--------
Id int
Name varchar
Files
--------
Id int
Userid int
Filename varchar
Stamp int (unix_timestamp)
The way I'm doing it now, I use SELECT DISTINCT to get all the users
with files, then a separate query for each user returned to retrieve
their latest file. This method requires many, many individual queries
to the database?
Any help is appreciated.
Thanks,
Mikey