Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-08-2009
Member
 
Join Date: Dec 2008
Posts: 69
How to Select max record in Oracle

How to find the Max records from the available records, I have oracle database and I wanted to write statement that returns the most recent revision date with the set of Records.. If anyone knows about this please let me know.
Reply With Quote
  #2  
Old 13-08-2009
Member
 
Join Date: Feb 2006
Posts: 172
Re: How to Select max record in Oracle

Select the max of your date column, and use a where clause about that column only for date less than today.

Code:
select a.sal 
 from emp a
  where 1=(select distinct(count(b.sal))
             from emp b
               where a.sal<=b.sal);

for second max

select a.sal 
 from emp a
  where 2=(select distinct(count(b.sal))
             from emp b
               where a.sal<=b.sal)
You can't group by GRP and also select ID. This doesn't make sense, because (to the DB) you might have two IDs with the same maximum DATE and GRP.
Reply With Quote
  #3  
Old 13-08-2009
Member
 
Join Date: Dec 2008
Posts: 161
Re: How to Select max record in Oracle

The number of factors that influences performance are so great that the best you could do is test both alternatives. you may use this query to join it with another query containing the IDs, If the response time is not good enough, then you must send details like:

SELECT MAX(ID) as maxid, GRP, MAX(DATE) AS max_date
FROM table
GROUP BY GRP
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Select max record in Oracle"
Thread Thread Starter Forum Replies Last Post
Select Unique Values (Selecting The Most Recent Record Based On Date) Leeland Software Development 4 14-05-2010 12:16 AM
Select unique columns from a record set Madhuchhanda Software Development 6 12-05-2010 11:31 PM
SELECT UNIQUE and SELECT DISTINCT TAARIQ Software Development 3 03-06-2009 10:00 PM
Windows DNS server - force A record to update PTR record Peter Cumming Windows Server Help 1 27-05-2006 07:00 PM


All times are GMT +5.5. The time now is 10:24 PM.