Get the last record alone from the select statement.

Поиск
Список
Период
Сортировка
Искать

Get the last record alone from the select statement.

От:
HK <harikrishnan@midascomm.com>
Дата:
Hi all,
  I have a doubt in limit clause. With limit and offset i can get the 
first few records from the select statement. Suppose i want to get the 
last record alone from the select, how can i achieve it.
I know this would have been answered many times, but i was not able to go 
thru the archieves.
Plz help me.

-- 
regards,
hari
      __
     / /    __  _  _  _  _ __  __         -o) 
    / /__  / / / \\// //_// \\ \\/ /         /\\\\  Making things happen
   /____/ /_/ /_/\\/ /___/  /_/\\_\\        _\\_v-  

-------------------------------------------------------------------

Re: Get the last record alone from the select statement.

От:
"A.Bhuvaneswaran" <bhuvan@symonds.net>
Дата:
> Hi all,
>   I have a doubt in limit clause. With limit and offset i can get the 
> first few records from the select statement. Suppose i want to get the 
> last record alone from the select, how can i achieve it.

=> select your_fields from your_table where your_condition order by 
oid desc limit 1;

regards,
bhuvaneswaran

Re: Get the last record alone from the select statement.

От:
Ron Johnson <ron.l.johnson@cox.net>
Дата:
On Fri, 2003-07-25 at 04:53, A.Bhuvaneswaran wrote:
> > Hi all,
> >   I have a doubt in limit clause. With limit and offset i can get the 
> > first few records from the select statement. Suppose i want to get the 
> > last record alone from the select, how can i achieve it.
> 
> => select your_fields from your_table where your_condition order by 
> oid desc limit 1;

Since oid is way non-standard, a better way may be:
=> select your_fields from your_table where your_condition order by 
your_fields desc limit 1;

-- 
+-----------------------------------------------------------------+
| Ron Johnson, Jr.        Home: ron.l.johnson@cox.net             |
| Jefferson, LA  USA                                              |
|                                                                 |
| "I'm not a vegetarian because I love animals, I'm a vegetarian  |
|  because I hate vegetables!"                                    |
|    unknown                                                      |
+-----------------------------------------------------------------+


FAQ