Re: newbie question for return date
Re: newbie question for return date
От:
Lee Harr <missive@frontiernet.net>
Дата:
In article , tviardot wrote: > Hi guys, here a newbies question. > I've made a table with some action and date. > How may i query the most recent date. (I'd like to return only the record > which have the most recent date ). > Tx > > How about: SELECT * FROM t ORDER BY d DESC LIMIT 1;
Re: newbie question for return date
От:
Medi Montaseri <medi.montaseri@intransa.com>
Дата:
Hey a suggestion, what if PG would support the negative limit as in select * from table limit -1 to mean limit it from the other end of list..... Sort of like some languages where they support array[1] vs array[-1]. I'm not sure, but it looks like order by will sort the list which is expensive and then allow us to get the first chunk specified by limit. Lee Harr wrote: >In article , tviardot wrote: > > >>Hi guys, here a newbies question. >>I've made a table with some action and date. >>How may i query the most recent date. (I'd like to return only the record >>which have the most recent date ). >>Tx >> >> >> >> > >How about: > >SELECT * FROM t ORDER BY d DESC LIMIT 1; > > >---------------------------(end of broadcast)--------------------------- >TIP 3: if posting/reading through Usenet, please send an appropriate >subscribe-nomail command to majordomo@postgresql.org so that your >message can get through to the mailing list cleanly > >
Re: newbie question for return date
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Medi Montaseri writes: > Hey a suggestion, what if PG would support the negative limit as in > select * from table limit -1 to mean limit it from the other end of > list..... You'd hardly want that, as it would necessarily be the slowest possible way of retrieving the rows you're after. Instead, reverse the sort order. For example select * from table order by datecol desc limit 1; regards, tom lane
Re: newbie question for return date
От:
terry@greatgulfhomes.com
Дата:
In order for your proposed result of array[-1] to be consistent/predictable, an ORDER BY sorting action will have to be performed *anyway* (in order to consistently return the last record(s) from the recordset), so doing an ORDER BY field_name DESC LIMIT 1 will have the same effect. Just my 2 cents Terry Fielder Network Engineer Great Gulf Homes / Ashton Woods Homes terry@greatgulfhomes.com > -----Original Message----- > From: pgsql-general-owner@postgresql.org > [mailto:pgsql-general-owner@postgresql.org]On Behalf Of Medi Montaseri > Sent: Monday, October 28, 2002 8:13 PM > To: missive@hotmail.com > Cc: pgsql-general@postgresql.org > Subject: Re: [GENERAL] newbie question for return date > > > Hey a suggestion, what if PG would support the negative limit as in > select * from table limit -1 to mean limit it from the other end of > list..... > > Sort of like some languages where they support > > array[1] vs array[-1]. > > I'm not sure, but it looks like order by will sort the list which is > expensive and then > allow us to get the first chunk specified by limit. > > Lee Harr wrote: > > >In article , > tviardot wrote: > > > > > >>Hi guys, here a newbies question. > >>I've made a table with some action and date. > >>How may i query the most recent date. (I'd like to return > only the record > >>which have the most recent date ). > >>Tx > >> > >> > >> > >> > > > >How about: > > > >SELECT * FROM t ORDER BY d DESC LIMIT 1; > > > > > >---------------------------(end of > broadcast)--------------------------- > >TIP 3: if posting/reading through Usenet, please send an appropriate > >subscribe-nomail command to majordomo@postgresql.org so that your > >message can get through to the mailing list cleanly > > > > > > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to > majordomo@postgresql.org) >