HowTO: Get only one entry which has the highest value in a specific column?

Hi there,
ich have the following problem. I want to write logs in a table. One column is the date of the log and some others hold the information.
Now I want to get the last log and I it should be good performance too.
What would you suggest?
At the moment I think about the max() function. Is it a solution?
Would a view which orders the logs by date (DESC) improve performance? maybe the view could create a collum which numbers the logs beginning by the newest.
something like: ...ROW_NUMBER() OVER(ORDER BY logdate) AS indx ...
Thx in advance
Dominik

In my opinion SELECT * FROM MY_LOG WHERE LOG_DATE =
MAX(LOG_DATE) could be expensive (performance)In the first place, it issues an error saying GROUP functions are not allowed here.
MAX() solution would be better.
SQL> explain plan for select *
  2                   from (select emp.* , row_number() over (order by hiredate desc) rn
  3                         from emp)
  4                   where rn = 1;
Explained.
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id  | Operation                |  Name       | Rows  | Bytes | Cost  |
|   0 | SELECT STATEMENT         |             |    16 |  1760 |     4 |
|*  1 |  VIEW                    |             |    16 |  1760 |     4 |
|*  2 |   WINDOW SORT PUSHED RANK|             |    16 |   704 |     4 |
|   3 |    TABLE ACCESS FULL     | EMP         |    16 |   704 |     2 |
Predicate Information (identified by operation id):
   1 - filter("from$_subquery$_001"."RN"=1)
   2 - filter(ROW_NUMBER() OVER ( ORDER BY "EMP"."HIREDATE" DESC )<=1)
Note: cpu costing is off
17 rows selected.
SQL>
SQL> explain plan for select emp.* from emp
  2                   where hiredate = (select max(hiredate)
  3                                     from emp);
Explained.
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
|   0 | SELECT STATEMENT     |             |     1 |    44 |     2 |
|*  1 |  TABLE ACCESS FULL   | EMP         |     1 |    44 |     2 |
|   2 |   SORT AGGREGATE     |             |     1 |     9 |       |
|   3 |    TABLE ACCESS FULL | EMP         |    16 |   144 |     2 |
Predicate Information (identified by operation id):
   1 - filter("EMP"."HIREDATE"= (SELECT /*+ */
              MAX("EMP"."HIREDATE") FROM "EMP" "EMP"))
Note: cpu costing is off
17 rows selected.
SQL> Cheers
Sarma.

Similar Messages

  • To find the number that has the highest value

    I have an internal table with one field containing numeric values. I want to know the number that has the highest value. Can you tell me how do I do that?
    Is there any keyword for this?
    Thank you,
    Krishen

    Hi,
      Use the below procedures..
    <b>CASE 1</b>
    SORT <itab> by <Fld>
    where <itab> - Internal Table.
    and <Fld>     - Field Name ( in your case it is the field with numeric values)
    describe table <itab> lines <no_of_lines>
    <no_of_lines> - total number of lines in the table.
    read table <itab> index <NO_OF_LINES>
    the above read statement gives the highest record.
    <b>CASE 2</b>
    SORT <itab> by <Fld> descending.
    where <itab> - Internal Table.
    and <Fld>     - Field Name ( in your case it is the field with numeric values)
    read table <itab> index 1.
    the above read statement gives the highest record.
    I hope this solves your problem.
    Regards,
    Vara

  • How do I get proof of purchase which has the IMEI number for my phone?

    For my insurance I will need to supply a proof of purchase that includes the IMEI number on it.
    I ordered my iphone online from the UK Apple store and the invoice does not have the IMEI number on it.
    Any ideas on how I can get some proof of purchase with the IMEI number on it?

    What would an insurance company need the iMEi number for ?
    It has nothing to do with them.
    If the phone has been lost/stolen then sure your mobile operator needs to know so they can block it but not your insurance company.
    By the way its recorded with in your computer Itunes backup if you want to find it.
    For security reasons Apple would never show an iMEi number on a receipt thats likely disgarded.
    It is however on the box on a sticker underneath.

  • Howto close only one JFrame, and not the whole Application?

    I hava a Application (Just a JFrame).
    I open a new JFrame doing some Wizard stuff.
    The user should close the Wizard with the Window-Closer [x].
    But: all open Frames dispose. How can i prevent that?
    The Application uses:
             setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            System.gc();
            System.exit(0);
            //or alternative: dispose();
    });The second JFrame uses:
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            frame.dispose();
    });

    System.exit(0) will close all windows in an application if you use it, as it will kill the whole program you have launched from the command-line, you need to call frame.dispose()

  • To Get List of Tables from Database which has the data 'AAAA' - T-SQL Query

    Hi,
    I have a database "Adventureworks", I need to get list of tables, which has the data 'AAAA' in their rows.
    Is there any optimised or simple way to do this task?
    Any T-SQL Query Available
    --- Thanks in advance..

    You can refer the same below URL provided by Praveen:
    https://gallery.technet.microsoft.com/scriptcenter/c0c57332-8624-48c0-b4c3-5b31fe641c58
    It has the SQL SP - "SP_SearchTables". You can pass parameters the way you want and get the expected output.
    -- Search for 'bike' instead of 'AAAA'
    Use AdventureWorks2012
    EXEC SP_SearchTables @Tablenames = '%', @SearchStr = '%bike%'
    -Vaibhav Chaudhari

  • I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page word document, some recipients get only one page.  Also sometimes when I burn an image from iPhoto on to a disc, only part of the image appears.  Why?

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

  • When I take my phone off charge in the morning I get an info box on the front which has the sound trumpet icon with a line through it and the word Mute.  The only way to get rid of it is to reboot the phone any ideas as to how I can stop this happening?

    When I take my phone off charge in the morning I get an info box on the front which has the sound trumpet icon with a line through it and the word Mute.  The only way to get rid of it is to reboot the phone any ideas as to how I can stop this happening?

    Hello cor-el, thanks for your reply. I changed my settings for downloads to desktop and it has appeared on there. When I double click I am asked which program I want to open file. I click firefox and another box "opening install" says I have chosen to open the file which is an application and do I want to save it. This is the only real option so I press save file. I get a box saying this is an executable file which may contain viruses - do you want to run. I press ok and the final box showing C drive file name and desktop appears stating application not found.
    This happens the same whenever I try to install.
    To my untrained eye the application is not being recognised as an application and I cannot work out how to get it to do that.
    My plugin is still showing as out of date.
    Is there anything you could suggest. Thanks for your time.

  • I created a photo album on my iPhone 4s - edited photos etc. but I cannot figure out how to transfer it to my pc (using Windows 8).  The only folder in the iphone drive is the one which has the Camera roll photos :( Help please - I really need the photos!

    I created a photo album on my iPhone 4s - edited photos etc. but I cannot figure out how to transfer it to my pc (using Windows 8).  The only folder in the iphone drive is the one which has the Camera roll photos Help please - I really need the photos!

    The camera roll is not part of the sync process at all.
    You should be importing these photos to your computer regularly as you would with any digital camera.  Youc an organize them on your computer and sync the to the iphone if you wish.
    The photos sync from the computer to the iphone is one way.
    The iphone mirrors the selected content of the computer to which it is synced.

  • I'm not able to install windows 7 in my imac 21' which has the latest OSX 10.9  It keeps saying that I need a 64bit version of win7 which i actually have but it doesn't seems to be recognize as one.

    I'm not able to install windows 7 in my imac 21' which has the latest OSX 10.9
    It keeps saying that I need a 64bit version of win7 which I actually have but it doesn't seems to be recognize.
    Can someone help me out?
    Thank you

    To my knowledge there are no official MS Windows DVDs that contain both the 32 and 64 bit versions. There is a way to make a USB thumb drive that has both bit version on it but AFAIK this can't be done on a DVD disc even with a Dual Layer DVD disc.
    For the Windows installer to function, actually boot the system to the install routine, certain files have to be on a certain area of the DVD disc. If by chance you really do have a DVD disc that contains both bit versions your Mac is only seeing the 32bit version on that disc.
    You'll need to get a Real MS DVD of just the 64bit version or download the 64bit version ISO from My Digital Life and burn it to a DVD disc.
    Pedroapple wrote:
    In fact i'm using a DVD with both 32 and 64-bit win7. But it's the only one I have. I don't want to install the newest Win 8.
    So you're saying there is no solution for this?
    Thank you so much for your response.

  • HT201342 How will this benefit me. I have a Mac computer that i upgraded to Mountain lion, a macbook pro and an iPhone 4s which has the latest software. all i want is simplicity and to have one email account which which will not duplicate everything 4 or

    I have been asked to set up an Icloud account by Apple.
    How will having another icloud email benefit me. I have my work email which is all i require, but had to set up a @me account to get email on my Macbook.
    I have a Mac computer that i upgraded to Mountain lion, a macbook pro and an iPhone 4s which has the latest software. all i want is simplicity and to have one email account which which will not duplicate everything 4 or 5 times.
    My notes are duplicated, i have to delete my emails individually on all devices so whenever i put my phone on, all the emails i have deleted at work re-appear on my phone and again the same thing happens on my Macbook pro. I seem to spend all my time deleting emails 3 times.
    Is there something simple in the set up of these that i am missing?
    Any help would be appreciated

    I have been asked to set up an Icloud account by Apple.
    How will having another icloud email benefit me. I have my work email which is all i require, but had to set up a @me account to get email on my Macbook.
    I have a Mac computer that i upgraded to Mountain lion, a macbook pro and an iPhone 4s which has the latest software. all i want is simplicity and to have one email account which which will not duplicate everything 4 or 5 times.
    My notes are duplicated, i have to delete my emails individually on all devices so whenever i put my phone on, all the emails i have deleted at work re-appear on my phone and again the same thing happens on my Macbook pro. I seem to spend all my time deleting emails 3 times.
    Is there something simple in the set up of these that i am missing?
    Any help would be appreciated

  • How to create a table which have always only one entry inside it?

    Hi Experts,
    Is it possible to create a table in data dictionary which have always only one entry inside it. If  we insert another entry, then it should throw an error.

    if  you want to   maintain  only one data  in that  ...   then
    first  time   for  making  one  data entry     in the <b>Delivery & maintaince   </b> tabstrip  in the   table  have an  option   <b>Display /maintaince Allowed ...</b>
    after that
    change  it to  <b>Display/maintianance allowed  Restrictions .</b> ...  so that  table will not  allow to insert the entries .
    reward  points if it is usefull ....
    Girish

  • I cannot add a Wi-Fi guest network. Gone to Utilities Airport Utilities and all get is an image/browser of my Airport Extreme. Looking for the browser which has the title Wireless but cannot find anywhere. I need help?

    I cannot add a Wi-Fi guest network. Gone to Utilities>Airport Utilities and all I get is an image/browser of my Airport Extreme. Looking for the browser window which has the title Wireless but cannot find anywhere. What am I doing wrong?

    Open AirPort Utility. The first screen looks something like this:
    Click on the AirPort Extreme and another screen will appear. Click Edit, then the window with the Wireless tab will appear.
    If you do not see these screens, you will need to start over and configure your AirPort again.

  • I have two apple accounts and one of which has my music on. I would like to move this music to the other account. Is there a simple way of doing this?

    I have two apple accounts and one of which has my music on. I would like to move this music to the other account. Is there a simple way of doing this?

    There is currently no way to merge accounts.  The best option is to pick one, and use it consistantly.
    HTH.

  • When I plug my iphone in to my USB port in the car or computer I get an error message which says the USB has exceeded it power limit

    When I plug my iphone in to my USB port in the car or computer I get an error message which says the USB has exceeded it power limit.
    What can I do?

    madonnafromqld wrote:
    When I plug my iphone in to my USB port in the car or computer I get an error message which says the USB has exceeded it power limit.
    What can I do?
    Stop doing that.

  • The toolbar which has the go back button, refresh button, etc. is gone. How do I get it back?

    The tool bar which has the url of the page I am on, go back button, refresh button, etc. is gone. How do I get it back?
    == This happened ==
    Just once or twice
    == a couple weeks ago.

    The toolbar which has the view button is also missing.

Maybe you are looking for