Try this:
SELECT
(SELECT <your_column>
FROM <your_table>
ORDER BY <your_column> offset 0 LIMIT 1) ,
(SELECT <your_column>
FROM <your_table>
ORDER BY <your_column> OFFSET (SELECT COUNT(*) ) LIMIT 1)
FROM <your_table> LIMIT 1;
SELECT
(SELECT <your_column>
FROM <your_table>
ORDER BY <your_column> offset 0 LIMIT 1) ,
(SELECT <your_column>
FROM <your_table>
ORDER BY <your_column> OFFSET (SELECT COUNT(*) ) LIMIT 1)
FROM <your_table> LIMIT 1;
On Wed, Sep 2, 2015 at 7:27 PM, Rob Sargent <robjsargent@xxxxxxxxx> wrote:
If you're ordering by col1, doesOn 09/02/2015 05:14 PM, Tom Smith wrote:
Thanksfunctions as it has many use casesI am wondering why these two functions are not part of postgresql built-into do this. Is it widely used and reliable?I saw some posting in wiki with a custom function (or C extention)select first(col1), last(col1) from table order by col1Hi:I need to get the first and last tow in one sql like below
https://wiki.postgresql.org/wiki/First/last_(aggregate)
select min(col1), max(col1) from table order by col1not do the trick;
--
Melvin Davidson
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.