Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBs36-0003cx-RO for pgsql-admin@arkaria.postgresql.org; Sat, 20 May 2017 00:15:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dBs35-00061i-7U for pgsql-admin@arkaria.postgresql.org; Sat, 20 May 2017 00:15:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dBs33-000603-Me for pgsql-admin@postgresql.org; Sat, 20 May 2017 00:15:09 +0000 Received: from mail-qk0-x22c.google.com ([2607:f8b0:400d:c09::22c]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dBs2u-0003H0-DU for pgsql-admin@postgresql.org; Sat, 20 May 2017 00:15:08 +0000 Received: by mail-qk0-x22c.google.com with SMTP id a72so73127266qkj.2 for ; Fri, 19 May 2017 17:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=liEoMjJf7DXlAbnThvzZp5J+duBV3d1f0x+sOxe/PG4=; b=yLnl7pcQJ0lj5y1nSio7prvILil/7xWVDW+CwrAgXIWJFDC2kCjwaODUFQYAb1H8gX hY4Z+3SWxWdBOegmnC+srn0GAWhUYubBrHknuBYOyvTbtPWBqr+8m+uVAZtUrGKtInlu uYIuCeUYUcjKr6/+FjihBFsKKN1wo0Q6M7DBI0C1XhYf0Tt462Mc7Iphda926nfbMI76 pooHKnAgfpi8kNYrVhVGCdf/d5iG94LqyyWIi/h8rga9vt4poTvMdgPDzPW80uHsZREl H0aiXcmiBc47JIFu9GJ1Tebz1vA3P1dnP5sVbt0k6JQ9ihEmHBC0DVeTkRUkiQ4ReAdE csfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=liEoMjJf7DXlAbnThvzZp5J+duBV3d1f0x+sOxe/PG4=; b=Ai6+O7wU+A37JvodeZJR40BhXm6ODHdNt7xvswy/aSwZ4TdFEH+oKlPOI7E8NEvCXP syq6Zxj+o8yKWTngWo/7qHFCAba5edivSiE2hsxjNAg4jT2M+vNRZ6RHMzP1vUgwWubW AYA1/v+0R6pSvYXp1YHXVwEfYUdywBI/0+CZ7ONw3xWbKTk/F9oMiGAVTqQCAFykLJp2 MCXocKCJgeRQiDQBuGZHirMQOK3NByaOasK51sJDJxi9wGBsmUwSsu0TYeq9DhFA1lu1 JEU/0erxIboERELmHqWF+Mp5gGDWM0WG3ubgfqNBfCkhx7CTjIWZ3kkJPbKMVT2Fpvum /KKA== X-Gm-Message-State: AODbwcD41Z+v1pM1g2oNWDgOohUqfbLUrhojBO/+CkVvbGGx/lL4DfTR TFJ6QQaCXvDWbL6ekBM= X-Received: by 10.55.101.20 with SMTP id z20mr10489970qkb.148.1495239298527; Fri, 19 May 2017 17:14:58 -0700 (PDT) Received: from alvin.alvh.no-ip.org ([190.217.209.130]) by smtp.gmail.com with ESMTPSA id s190sm6872854qkh.57.2017.05.19.17.14.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 17:14:58 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id E1E49338; Fri, 19 May 2017 20:14:50 -0400 (-04) Date: Fri, 19 May 2017 20:14:50 -0400 From: Alvaro Herrera To: "MAJUMDER, SAYAN" 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. Message-ID: <20170520001450.4ms3d3iqkx4c6ehh@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <41D6D8A91714DB4BB816A7D4AECA939909D73E3D@IN-BLR-DAGND1.corp.capgemini.com> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org 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 > 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