Re: SQL Troubles with JOIN, GROUP BY and MAX???

From: Date: Tue, 04 Jun 2002 06:58:58 +0000
Subject: Re: SQL Troubles with JOIN, GROUP BY and MAX???
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-19593@lists.php.net to get a copy of this message
Try something like this: SELECT USERS.Username,FILES.Filename FROM USERS LEFT JOIN FILES USING(Id) WHERE FILES.Filename IS NOT NULL ORDER BY FILES.Stamp DESC LIMIT 1; If Filename declared as NOT NULL then use FILES.Filename!='' MR> I've been racking my brain for too long on this one, can someone help me MR> out with a SQL query? MR> I've got 2 tables in a mySQL database, 'users' and 'files' defined MR> as MR> such: MR> USERS MR> ------------------- MR> Id int (autoincrement) MR> Username varchar MR> FILES MR> ------------------- MR> Id int (autoincrement) MR> Userid int MR> Stamp int (holds unix_timestamp for MR> filectime($filename)) MR> Filename varchar MR> What I want is a single query that returns all of the users that have MR> submitted files, and only the MOST RECENT file for each user. I'm sure MR> I need a GROUP BY and/or a MAX() in there somewhere..... -- Best regards, Evgeny mailto:gecka@baik.ru

« previous php.db (#19593) next »