Hi all, I am writing a PHP web page that displays some statistics based on information in a database.
The database has a table (stats) with three fields: ID, Sender, Text, UserID, Timestamp I have set it up so that I get basic statistics with the following query: SELECT Text, Count(*) FROM stats WHERE UserID='1' GROUP BY Text What I would also like to do is get the stats for unique Senders, such that if there are multiple entries for a particular Sender, it is only counted once and it is grouped under the first (chronologically) entry. Example (fixed font): ID Sender Text UserID Timestamp 1 a One 1 20020918150000 2 b One 1 20020918151000 3 c Two 1 20020918152000 4 d Two 1 20020918153000 5 a Two 1 20020918154000 This currently gives me the following output: One, 2 Two, 3 What I would like is: One, 2 Two, 2 i.e. data from sender 'a' is only counted once and is counted as "One". Can I do this with an SQL query, nested or otherwise, or do I need to go through the rows one by one in the PHP code? Many thanks, Ben --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php