Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • UTL_FILE test program Oracle
  • Optimizer SORT Operations Oracle
  • Oracle Connections expire_time and firewall Oracle
  • age_alert.ksh aging out alert.log Linux/Unix
  • How to find pinned objects from shared pool. (pinned via dbms_shared_pool.keep) Oracle
  • My Minimum Tuning Programs Oracle
  • plan10g.sql good Oracle
  • Vivek Tuning for Row Locks. Oracle
  • find the files that are 1 day old. Linux/Unix
  • Complete Git Tutorial for Beginners GIT
  • Roles and Stored Object behaviour Oracle
  • Removing Blank lines from file using grep Linux/Unix
  • Monitor and Trace Unix processes using truss Linux/Unix
  • Default User Profile Oracle
  • oracle_env_10g_CADEV Linux/Unix

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

  • findx.sql /* Find Indexes on specified USER.TABLE_NAME */ Oracle
  • plan10g.sql good1 Oracle
  • RMAN : Consistent Backup, Restore and Recovery using RMAN Oracle
  • ORA-4031 issue and solution on 09-MAY-2008 Oracle
  • DBMS_UTILITY PACKAGE Oracle
  • sess1.sql 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 (395)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (343)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • prepfiles.sh for step by step generating pending statistics files10-Mar-2026
  • tracksqltime.sql05-Mar-2026
  • 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

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • sql_plan9i.sql Oracle
  • oracle tips… from http://www.bijoos.com/oracle/douknow.htm Oracle
  • Trace a SQL session from another session using ORADEBUG Oracle
  • To seee semaphores and shared memory segments in Solaris Linux/Unix
  • Move WordPress site from one hosting service to other. PHP/MYSQL/Wordpress
  • Difference between SYNC and AFFIRM Oracle
  • Roles and Stored Object behaviour Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme