From: | FC <lne-1mc8(at)myamail(dot)com> |
---|---|
To: | jim(at)contactbda(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: SQL question. |
Date: | 2005-06-01 15:49:25 |
Message-ID: | F6A98A08-7E85-41A4-BEB3-AACFB7C9630B@myamail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I need to remember to keep things simple...
Works fine, thanks.
Fred
On Jun 1, 2005, at 5:20 PM, Jim Buttafuoco wrote:
> how about (untested)
>
> select *
> from
> (
> SELECT DISTINCT ON (linkid) *
> FROM all_links
> WHERE uid='2' AND DATE_TRUNC('day',read_date) = DATE_TRUNC
> ('day',TIMESTAMP '2005-06-01')
> ORDER BY linkid
> ) A
> ORDER BY read_date DESC limit 100
>
>
> ---------- Original Message -----------
> From: FC <lne-1mc8(at)myamail(dot)com>
> To: pgsql-general(at)postgresql(dot)org
> Sent: Wed, 1 Jun 2005 16:40:48 +0200
> Subject: [GENERAL] SQL question.
>
>
>> Hello SQL Aces !
>>
>> I want to do a select on a table distinct on linkid and sorted by
>> date. I have try this
>>
>> SELECT DISTINCT ON (linkid) * FROM all_links
>> WHERE uid='2' AND DATE_TRUNC('day',read_date) = DATE_TRUNC('day',
>> TIMESTAMP '2005-06-01') ORDER BY linkid, read_date;
>>
>> With this request "works" but the raws are sorted as I want. To have
>> the rows sorted by date I have done this using a temporary table and
>> that works exactly as I want.
>>
>> CREATE LOCAL TEMP TABLE temp_links WITHOUT OIDS AS
>> SELECT DISTINCT ON (linkid) * FROM all_links
>> WHERE uid='2' AND DATE_TRUNC('day',read_date) = DATE_TRUNC('day',
>> TIMESTAMP '2005-06-01') ORDER BY linkid;
>>
>> SELECT * from temp_links ORDER BY read_date DESC limit 100
>>
>> My question is... How can I do the same thing in the more efficient
>> way and without using a temporary table. Since I am using PHP and the
>> table is not deleted at the end of the program because PHP keeps the
>> connection to the database open.
>>
>> Thanks for any suggestions.
>> Fred
>>
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 2: you can get off all lists at once with the unregister command
>> (send "unregister YourEmailAddressHere" to
>> majordomo(at)postgresql(dot)org)
>>
> ------- End of Original Message -------
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Gerald D. Anderson | 2005-06-01 15:51:32 | Re: Old problem needs solution |
Previous Message | Richard_D_Levine | 2005-06-01 15:49:21 | Re: [UMN_MAPSERVER-USERS] FYI: Google to pay student open source developers |