Display Middle Record

How to display middle record in a given table?

Questions by shameem_chandu

Showing Answers 1 - 18 of 18 Answers

taaznyonker

  • Mar 31st, 2010
 

BELOW example will give the middle row of the table(not sorted).

eg:

SELECT * FROM EMP WHERE ROWNUM <=(SELECT COUNT(1)/2 FROM EMP)
MINUS
SELECT * FROM EMP WHERE ROWNUM <(SELECT COUNT(1)/2 FROM EMP)

  • Aug 11th, 2011
 

The following query works as follows: If the table has ten records, it will display the 5th and 6th record and if it has some 11 records, will display 6th record alone.

Code
  1.  

  Was this answer useful?  Yes

sampra

  • Mar 6th, 2012
 

SELECT * FROM EMP WHERE ROWNUM <=(SELECT COUNT(1)/2 FROM EMP)
MINUS
SELECT * FROM EMP WHERE ROWNUM >=(SELECT COUNT(1)/2 FROM EMP)

  Was this answer useful?  Yes

Nazeera Jaffar

  • Sep 26th, 2012
 

The below code returns the rows from 50-74

Code
  1.  

  Was this answer useful?  Yes

Nazeera Jaffar

  • Sep 26th, 2012
 

The below code selects the exact middle row from the table

Code
  1.  

  Was this answer useful?  Yes

Naveen Hokrana

  • Feb 2nd, 2016
 

Code
  1.  

  Was this answer useful?  Yes

Shivam

  • Feb 13th, 2016
 

WRONG You cannot put = in rownum

  Was this answer useful?  Yes

It will not work
SELECT * FROM EMP WHERE rownum=trunc(SELECT count(*)/2 FROM EMP)
Error at Command Line : 42 Column : 38
Error report -
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:

Code
  1. span style="color: #ff0000;">"missing expression"

  Was this answer useful?  Yes

Visal

  • Aug 13th, 2016
 

Code
  1.  

  Was this answer useful?  Yes

Kaushik

  • Aug 7th, 2017
 

Code
  1.  

  Was this answer useful?  Yes

SATHIS KUMAR

  • Jan 23rd, 2018
 

SELECT * FROM (SELECT ROWNUM ID,E.* FROM EMP E) WHERE ID IN (SELECT COUNT(*) FROM EMP)

Code
  1.  

  Was this answer useful?  Yes

mahesh

  • Feb 8th, 2018
 

>= is not working in rownum
check it once

  Was this answer useful?  Yes

Manthan

  • Aug 21st, 2018
 

Its displaying:
ERROR at line 1:
ORA-00936: missing expression

  Was this answer useful?  Yes

shreyas varchasvi

  • Oct 15th, 2018
 

in rownum we cant use >= operator, only < ,< = operator will work.

  Was this answer useful?  Yes

Bibhudatta Panda

  • Jun 18th, 2019
 

Suppose I want middle record 5-9 records

Code
  1.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions