Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • My FTP Job Scheduling for www.pvmehta.com PHP/MYSQL/Wordpress
  • MYSQL for Oracle DBA MYSQL
  • Good Site for Oracle Internals Oracle
  • Useful Solaris Commands on 28-SEP-2005 Linux/Unix
  • ext#.sql Oracle
  • currwait.sql Oracle
  • replace alphabets using sed Linux/Unix
  • Wait.sql Oracle
  • Mutating Table Error while using database trigger Oracle
  • copying/removing directory with all its subdirectory Linux/Unix
  • How do I get Oracle to automatically start when my server boots up? Oracle
  • get_aix_vmstat.ksh Oracle
  • database trigger failing Oracle
  • Jai Shree Ram Oracle
  • Physical Standby switchover with session active Oracle

Find nth max and min.

Posted on 02-May-2007 By Admin No Comments on Find nth max and min.

First, the query for Max:

SELECT * FROM TAB1 a

WHERE &N = (SELECT count(DISTINCT(b.col1))

FROM TAB1 b WHERE a.col1<=b.col1) Next, the query for Min:
SELECT * FROM TAB1 a

WHERE &N = (SELECT count(DISTINCT(b.col1))

FROM TAB1 b WHERE a.col1>=b.col1)

If N=1 will return first max or first min. N=2 will return second max or min.

Oracle, SQL scripts

Post navigation

Previous Post: DBMS_Shared_pool pinning triggers
Next Post: Changing Instance Name ( No DB_NAME)

Related Posts

  • Locktree.sql Oracle
  • dbinv.sql Oracle
  • 10g RAC: Troubleshooting CRS Root.sh Problems Oracle
  • How to choose Driver table in SQL statement Oracle
  • VIvek Encryption Package and Its Usage Oracle
  • oracle fast start failover best practice Oracle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (342)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • Complete Git Tutorial for Beginners25-Dec-2025
  • Postgres DB user and OS user.25-Dec-2025
  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • Creating never expiring DB user accounts in Oracle Oracle
  • DBMS_PROFILER for tuning PLSQL programs. Oracle
  • ORA-00064: object is too large to allocate on this O/S during startup Oracle
  • How to know current SID Oracle
  • Small sample shell program Linux/Unix
  • Reclaim temp tablespace for oracle 8, 8i Oracle
  • How to know Number of CPUs on Sun Box Linux/Unix
  • OEM-Commnds Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme