RE: [PHP] group by get last record
| From: | Don Read | Date: | Sun, 16 Mar 2003 16:47:05 +0000 |
| Subject: | RE: [PHP] group by get last record | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-139847@lists.php.net to get a copy of this message | ||
<db list removed>
On 16-Mar-2003 Daniel Harik wrote:
> Hello,
>
> Guys i try to join to tables
>
> slides:
> id
> userid
> file
> moment
>
> users
> id
> username
>
> As there few slids per user and i want to get only last one, i use
> following
> sql query, but it fetches me first slide. How can i make it fetch last
> one
> please?
>
> SELECT slides.file, slides.moment, users.id, users.username FROM slides,
> users where users.id=slides.userid GROUP BY users.id desc
>
Which record is 'last' ?
There is no order to the records without an 'ORDER BY' clause.
If you figure that out, you can use a temporary table with all the
desired fields and with the userid as primary key.
Then do 'REPLACE INTO temptbl SELECT ... ORDER BY whatever'.
And finally do a 'SELECT * FROM temptbl'
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.