RE: [PHP] Re: [PHP-DB] Query - Grouping Results
| From: | Jeff Armstrong | Date: | Mon, 19 Mar 2001 16:06:35 +0000 |
| Subject: | RE: [PHP] Re: [PHP-DB] Query - Grouping Results | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-7601@lists.php.net to get a copy of this message | ||
Not a good idea! You have added a group by clause without
specifying any group functions on the non-group fields.
That path leadeth to much frustration, and eventually
to sql damnation! As the doco says, the results become
indeterminate.
Methinks what he actually wants is a SELECT DISTINCT
and a DATE_FORMAT on the time to get one record per
user per date.
Regards
Jeff
-----Original Message-----
From: Mario Henrique Cruz Torres [mailto:mario@mitus.com.br]
Sent: Monday, March 19, 2001 3:58 PM
To: Jordan Elver
Cc: PHP Database Mailing List; PHP General Mailing List
Subject: [PHP] Re: [PHP-DB] Query - Grouping Results
You can put this :
SELECT users.name AS name, user_logins.ip AS ip,
UNIX_TIMESTAMP(user_logins.time) AS time FROM users, user_logins WHERE
user_logins.user_id = users.id ORDER BY time ASC GROUP BY users.name
See the GROUP BY statement at mysql docs.
Mario H.C.T.
Jordan Elver wrote:
> Hi,
> I've got a table like:
>
> id user_id ip time
> 1 2 127.0.0.1 20010316105018
>
> Etc, etc.
>
> I do a join on the this table and the users table to get the coresponding
> username to user_id like this:
>
> SELECT users.name AS name, user_logins.ip AS ip,
> UNIX_TIMESTAMP(user_logins.time) AS time FROM users, user_logins WHERE
> user_logins.user_id = users.id ORDER BY time ASC
>
> How can I display the results grouped by username?
>
> So, I want to be able to display:
>
> Logins for John
>
> Thursday 10th
> Friday 12th
> Monday 23rd
>
> Logins for Bob
>
> Monday 1st
> Tuesday 2nd
> Saturday 31st
>
> Thanks for any help,
>
> Jord
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net