From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: MAJUMDER, SAYAN <sayan.a.majumder@capgemini.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Not able to find an alternative for SELECT TOP n WITH TIES in postgresql which is available in sql server.
Date: Fri, 19 May 2017 20:14:50 -0400
Message-ID: <20170520001450.4ms3d3iqkx4c6ehh@alvherre.pgsql> (raw)
In-Reply-To: <41D6D8A91714DB4BB816A7D4AECA939909D73E3D@IN-BLR-DAGND1.corp.capgemini.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>
Hi Sayan,
I have CCed the pgsql-admin list here, in the hope that somebody might
reply (full question below). I think the answer to your question is to
use a window function.
Please make sure to always write to pgsql-admin@postgresql.org, not the
"-owner" address. Otherwise, your message never reaches the list.
MAJUMDER, SAYAN wrote on April 24th 2017:
> Hi,
> I am new to postgresql and we have a query in sql server that is SELECT TOP n WITH TIES column_name from table_name.
> This clause is used to retrieve all similar rows to a base result set.
> I am not able to find any similar clause in postgresql.
>
> Example in sql server:-
> We have a table with 6 entries 1 to 4 and 5 twice.
>
> SELECT TOP 5 WITH TIES *
> FROM MyTable
> ORDER BY ID;
>
> This will returns 6 rows, as the last row is tied (exists more than once.)
>
> Whereas
>
>
> SELECT TOP 5 *
>
> FROM MyTable
>
> ORDER BY ID;
>
> This will returns 5 rows as the last row is tied.
>
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
> [Email_CBE.gif]Thanks and regards,
> Sayan Majumder
> CSD | AppsTwo | Analyst A4
> Capgemini Technology Services India Limited| Kolkata |
> Tel.: +91 8584022251/ Ext.:- 3339161
> www.capgemini.com<http://www.capgemini.com/;
> People matter, results count.
>
>
> This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: alvherre@2ndquadrant.com, sayan.a.majumder@capgemini.com
Subject: Re: Not able to find an alternative for SELECT TOP n WITH TIES in postgresql which is available in sql server.
In-Reply-To: <20170520001450.4ms3d3iqkx4c6ehh@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox