Fetch the row with latest data,when multiple rows exist for same user

Hi ,
Thanks for reading the post.I have table with the follwoing data.
user requestdate createdate
jake 02/21/2006 15:33:41 02/25/2006 15:33:41
jake 04/20/2006 15:33:41 04/21/2006 15:33:41
jake 04/23/2006 15:33:41 04/24/2006 15:33:41
jill 02/21/2006 15:33:41 02/25/2006 15:33:41
jill 04/20/2006 15:33:41 04/21/2006 15:33:41
The data type of user,reqdate,createdate is varchar2.I want to write a query that
gives me all the users and his latest information.After running the query I am expecting the result
user requestdate createdate
jake 04/23/2006 15:33:41 04/24/2006 15:33:41
jill 04/20/2006 15:33:41 04/21/2006 15:33:41
I am not able to write the correct query.Need help , Thanks
Pandu

I am sorry Again,Here are the actual tables and the data in them.
SQL> desc test;
Name                                      Null?    Type
ID                                        NOT NULL VARCHAR2(22)
OBJECTNAME                                         VARCHAR2(30)
SQL> select id,objectname from test order by objectname;
ID                     OBJECTNAME
49                     Nani
43                     Nani
46                     jack
41                     jack
45                     jack
47                     jill
42                     jill
7 rows selected.
SQL> desc testattr;
Name                                      Null?    Type
ID                                        NOT NULL VARCHAR2(22)
ATTRNAME                                           VARCHAR2(22)
ATTRVALUE                                          VARCHAR2(22)
SQL> select * from testattr;
ID                     ATTRNAME               ATTRVALUE
41                     rdate                  02/21/2006 15:33:41
41                     cdate                  02/25/2006 15:33:41
45                     rdate                   04/20/2006 15:33:41
45                     cdate                  04/21/2006 15:33:41
46                     rdate                  04/23/2006 15:33:41
46                     cdate                  04/24/2006 15:33:41
42                     rdate                  02/21/2006 15:33:41
42                     cate                   02/25/2006 15:33:41
47                     rdate                  04/20/2006 15:33:41
47                     cdate                  04/21/2006 15:33:41
43                     rdate                  04/04/2006 14:33:41
43                     cdate                  04/05/2006 16:33:41
49                     rdate                  05/03/2006 09:32:55
49                     cdate                  05/05/2006 07:12:55
14 rows selected.All the attributes have data type varchar2.I want to write a query that gives the following result.
objectname               (attrvalue)requestdate                  (attrval)createdate
jack                            04/23/2006 15:33:41                    04/24/2006 15:33:41
jill                                04/20/2006 15:33:41                   04/21/2006 15:33:41
Nani                           05/03/2006 09:32:55                    05/05/2006 07:12:55.Thanks,Need help.
Pandu

Similar Messages

  • Query to get the record with latest date

    I have
    ACCOUNT_TABLE
    account_number
    account_event
    event_date
    ACCOUNT_TABLE
    1,Open,12 Jan 2006
    1,Open,13 Jan 2006
    1,Open,14 Jan 2006
    1,Open,15 Jan 2006
    1,Open,16 Jan 2006
    How can I get the latest record(16 Jan 2006) in one sql statement.
    Thx
    m

    if you have more account_event's then...
    SQL> with t as
      2   (select 1 account_number,'Open' account_event,'12 Jan 2006' event_date from dual union all
      3   select 1,'Open','13 Jan 2006' from dual union all
      4   select 1,'Open','14 Jan 2006' from dual union all
      5   select 1,'Open','15 Jan 2006' from dual union all
      6   select 1,'Open','16 Jan 2006' from dual union all
      7   select 1,'Close','17 Jan 2006' from dual union all
      8   select 1,'Close','18 Jan 2006' from dual union all
      9   select 2,'Open','19 Jan 2006' from dual)
    10   select * from t a
    11   where (a.account_number, account_event,a.event_date) in
    12   ((select b.account_number, account_event,max(b.event_date) from t b group by b.account_number,account_event))
    13  order by account_number;
    ACCOUNT_NUMBER ACCOU EVENT_DATE
                 1 Close 18 Jan 2006
                 1 Open  16 Jan 2006
                 2 Open  19 Jan 2006

  • How to extract the record with latest date

    in internal table i a have 10 records, in that for each record only date is changing...so,now the issue is i should extract the record which having the latest date

    try this code -
    data: begin of itab occurs 0,
          name(20),
          add(20),
          bp like sy-datum,
          end of itab.
    itab-name = 'aaa'.
    itab-add = '123'.
    itab-bp = '20061220'.
    APPEND ITAB.
    CLEAR ITAB.
    itab-name = 'bbb'.
    itab-add = '123'.
    itab-bp = '20061219'.
    APPEND ITAB.
    CLEAR ITAB.
    itab-name = 'aaa'.
    itab-add = '123'.
    itab-bp = '20061222'.
    APPEND ITAB.
    clear itab.
    sort itab descending by bp.
    read table itab index 1.
    write: itab.

  • I am transmitting data over internet and WiFi ,it's working fine with internet but when I choose WiFi for data transmission data is not being transmitted. What may be the possible issues of data transmission failure over WiFi?  Please help me.

    I am transmitting data over internet and WiFi ,it's working fine with Internet but when I choose WiFi for data transmission data is not being transmitted. What may be the possible issues of data transmission failure over WiFi?     Please help me....
    Thanks in Advance.
    Neeraj@iDev

    After a week's worth of debugging, I found the issue.
    The Java type returned from the call was defined as ArrayList.  Changing it to List resolved the problem.
    I'm not sure why ArrayList isn't a valid return type, I've been looking at the Adobe docs, and still can't see why this isn't valid.  And, why it works in Debug mode and not in Release build is even stranger.  Maybe someone can shed some light on the logic here to me.

  • Dynamic sql reurns no data when multiple values are passed.

    (Dynamic sql returns no data when multiple values are passed.)
    Hi,
    While executing the below dynamic sql in the procedure no data is returned when it has multiple input values.
    When the input is EMPID := '1'; the procedure works fine and returns data.Any suggestion why the procedure doen't works when input as EMPID := '1'',''2'; is passed as parameter?
    =======================================================
    create or replace PROCEDURE TEST(EMPID IN VARCHAR2, rc OUT sys_refcursor)
    IS
    stmt VARCHAR2(9272);
    V_EMPID VARCHAR2(100);
    BEGIN
    V_EMPID :=EMPID;
    stmt := 'select * from TEST123 where Empid is NOT NULL';
    IF V_EMPID <> '-1' THEN
    stmt := stmt || ' and Empid in (:1)';
    ELSE
    stmt := stmt || ' and -1 = :1';
    END IF;
    OPEN rc FOR stmt USING V_EMPID;
    END Z_TEST;
    ============================================================
    Script for create table
    ==================================================================
    CREATE TABLE TEST123 (
    EMPID VARCHAR2(10 BYTE),
    DEPT NUMBER(3,0)
    ===========================================
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('1',20);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('2',10);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('3',30);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('3',30);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('2',10);
    =============================================
    Select * from TEST123 where Empid in (1,2,3)
    EMPID DEPT
    1     20
    2     10
    3     30
    3     30
    2     10
    ===================================================================
    Any suggestion why the procedure doen't works when input EMPID := '1'',''2';?
    Thank you,

    The whole scenario is a little strange. When I tried to compile your procedure it couldn't compile, but I added the missing info and was able to get it compiled.
    create or replace PROCEDURE TEST (EMPID IN VARCHAR2, rc OUT sys_refcursor)
    IS
      stmt        VARCHAR2 (9272);
      V_EMPID     VARCHAR2 (100);
    BEGIN
      V_EMPID := EMPID;
      stmt := 'select * from TEST123 where Empid is NOT NULL';
      IF V_EMPID = '-1' THEN
        stmt := stmt || ' and Empid in (:1)';
      ELSE
        stmt := stmt || ' and -1 = :1';
      END IF;
      OPEN rc FOR stmt USING V_EMPID;
    END;If you pass in 1 as a parameter, it is going to execute because the statement that it is building is:
    select * from TEST123 where Empid is NOT NULL and -1 = 1Although the syntax is valid -1 will never equal 1 so you will never get any data.
    If you pass in 1,2 as a parameter then it is basically building the following:
    select * from TEST123 where Empid is NOT NULL and -1 = 1,2This will cause an invalid number because it is trying to check where -1 = 1,2
    You could always change your code to:
    PROCEDURE TEST (EMPID IN VARCHAR2, rc OUT sys_refcursor)
    IS
      stmt        VARCHAR2 (9272);
      V_EMPID     VARCHAR2 (100);
    BEGIN
      V_EMPID := EMPID;
      stmt := 'select * from TEST123 where Empid is NOT NULL';
      stmt := stmt || ' and Empid in (:1)';
      OPEN rc FOR stmt USING V_EMPID;
    END;and forget the if v_empid = '-1' check. If you pass in a 1 it will work, if you pass in 1,2 is will work, but don't pass them in with any tick marks.

  • Call the database table on commit operation and fetch the rows

    Hi
    I am new to Bpel. I have a task to call the database table on commit operation and fetch the rows and call a webservice iteratively for fetching the data into a file?
    Can anybody help me on this
    Thanks and regards
    Richa

    HI,
    update ZYBKP set MATNR = <b>zcore_2-ZDUMMY</b> where matnr = <b>zcore_2-ZDUMMY</b>.
    update ZY310 set MATNR = zcore_2-ZDUMMY where matnr = zcore_2-ZDUMMY.
    update ZYBCS_LOT set MATNR = zcore_2-ZDUMMY where matnr = zcore_2-ZDUMMY.
    <b>YOU ARE COMPARING SAME MATERIAL AND UPDATING WITH THE SAME..</b> AND ALSO ZCORE_2 IS A DATABASE TABLE AND MAY NOT CONTAIN ANY VALUE AT THAT POINT...
    in these statments you say that
    update table set matnr = 'MATNR' WHERE MATNR = 'MATNR'.
    EVEN THOUGH THIS STATMENT IS EXECUTED THERE WILL NOT BE ANY CHANGE IN THE TABLE...
    Thanks,
    Mahesh

  • Programming for changing the document of latest Date

    Hi,
    I am having requirement to change the Data of source items by picking the latest Date. There are several Source items(100). My question is how to write the code to change the data of several source items by pciking the latest date. I need to change the latest date( source item )and remaining source items data not to be changed.

    HI Sriram
      Sort by date descending and time. So that latest record you will get. For updating use only std FM and pass the necessary parameters. It will update with latest date.
    Regards
    vijay

  • How to create a textfile dynamically(with in the loop) with given data?

    Hi all,
    Can anyone Please guide me how to create a text file in the given path dynamically? (with in the loop) with given data.
    For example:
    <%
    String data1="name";
    String data2="address";
    for(int i=0;i<10;i++)
    create the textfile at c:/test/sample.txt//name of the each file created being "sample.txt"
    //contents of text file will be
    data1+i; //to get name1,name2.....
    data2+i// to get add1,add2........
    delete(sample.txt) //to enable to create another file in the loop with same name
    %>

    The code which Ashokan mentioned is not is not creating a file.
    i used code given below to create and write into it.
    But, not is writing into it. I don't konw, where i am going worng !
    Code
    String sample2="C:/Ash/sample2.txt";     
                                                                                    FileWriter fw = new FileWriter(sample2,true);
                                            BufferedWriter bw=new BufferedWriter(fw);
                                            bw.write("EMP ID");     
                                            bw.newLine();
    Please help
    Regards
    aSh

  • Im using iphone 4 uk unlock , it has ios 4.2.1 and it does not have software update option.Now i want to update the phone with latest ios is it possible and tel me how ?

    Im using iphone 4 uk unlock , it has ios 4.2.1 and it does not have software update option.Now i want to update the phone with latest ios is it possible and tel me how ?

    The update to iOS 5.0 & higher is an erase/restore deal, so make sure you follow the directions here to update your phone:
    http://support.apple.com/kb/ht4972
    iOS 7.0.4 will be installed.

  • Updated my iphone with iOS7.0.3, still dont have the option to reject the call or reject the call with a message when someone call and the phone is in the lock screen?

    Updated my iphone with iOS7.0.3, still dont have the option to reject the call or reject the call with a message when someone call and the phone is in the lock screen? I was of the impression that this issue will be fixed with updates. Please see the screenshot.

    Hello Beardsell,
    This is when the phone is unlocked mode. My snapshot is when the phone is locked.
    Remember when you get a call when the phone is locked and you used to have slide to answer in iOS 6 and if you slide up you would have options to reject, reject with a message and reject with a reminder. We dont have that in iOS 7. iOS 7 *****,  I cannot get back to iOS6, apple needs to be user friendly. Screen shot 1 when the phone is locked, screenshot 2 when the phone is unlocked.

  • HT1349 Mi itunes does not downloads latest swoftware when I click check for update it appears a sign that says "iTunes could not contact the iPod software update server because you are not connected to the internet" this happens even though I am connected

    My iTunes does not downloads the latest software when I click check for updates or download latest version, a message appears "iTunes could not contact the iPod sortware update server because you are not connectet to the internet" even though I am connected, can some body help me?

    If necessary, also see:
    iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server

  • Just updated from elements 11 to 13. When I try to use Levels in Elements 13. I click on the slider with my bamboo pen and nothing happens for a few seconds, sometimes not at all. This worked fine in Elements 11.

    Just updated from elements 11 to 13. When I try to use Levels in Elements 13. I click on the slider with my bamboo pen and nothing happens for a few seconds, sometimes not at all. This worked fine in Elements 11.

    Never mind my question on the photoshop elements 13 trying to install the camera raw update. It has been taken care of thank goodness!

  • What is the problem with IPhoto ´11 when I am uploading a photobook to apple store, there is always an error. Anyone ???

    What is the problem with IPhoto ´11 when I am uploading a photobook to apple store, there is always an error. Anyone ???
    evrything is right wite my appleID.

    First try to create a pdf file of the book as described in this Apple document: iPhoto '11: Preview a book, card, or calendar before you order or print it.
    If you are unsuccessful in creating the pdf file then boot into  Mac OS X: Starting up in Safe Mode and try again.  If that works you can continue and order the book while in Safe Mode. 
    Be sure to keep the pdf file of the book to compare with the printed copy when it arrives.
    OT

  • Table.rows.find() returns null in a table where the row exists.

    Hi...
    I am working in a Project in Visual Studio 2013 where I have to read an Excel report related with a list of business opportunities. Some of the Fields that are involved in it are:  Opportunity ID, BU, Account, close date, Account Manager,
    Total Value and so on. As soon as I get the conection with the Excel Report, I fill a DataTable and declare the columns [Opportunity ID] and [BU] as my Primary Keys.  In that way, an Opportunity value may have one o more rows
    with different BU code each of them.  In consequence, you can define one row in the table if you specify the [Opportunity ID] and the [BU] values.
    My problem starts when I try to get information of those rows that have an specific value of [Opportunity ID]. For that situation I make a "foreach" structure where I check the BU codes that are involved with that Opportunity. So
    I use the Find() Method to get the information of the row specified by the Opportunity ID and BU.  The first time it goes to find the information it gets the results successfully but in the next cycle changing just the [BU] using the same [Opportunity
    ID] value, the find() method returns a "null" and I do not know why because I am sure that the row exists in the table.  I have verified the "Unique" property for the  [Opportunity ID] and [BU] columns (which are
    my primary keys)  and they are in false which is OK.
    I share the code that I am using...
    Hope someone can help.
    Thanks.
    Alfmar.
    void ObtenTotalesxBUs(string Opportunity, string[] BUs, Object[] TotalBUs, Object[] ExpTotalBUs)
    ArrayList TotalesBUs = new ArrayList(); //Required information from the row.
    ArrayList ExpTotalesBUs = new ArrayList(); //Required information from the row.
    foreach(string businessUnit in BUs)
    Object[] LlaveBusqueda = { Opportunity, businessUnit }; //Provide values to the Primary Keys.
    DataRow RenglonInfo = null;
    RenglonInfo = TablaFunnel.Tabla.Rows.Find(LlaveBusqueda); //Find method receives the Primary Keys values. Here is where I have a "null" in return the second time changing just the [BU] field.
    TotalesBUs.Add(RenglonInfo["Total"]); //Get the required information from the row.
    ExpTotalesBUs.Add(RenglonInfo["Expected Total Value"]); //Get the required information from the row.
    TotalBUs = TotalesBUs.ToArray();
    ExpTotalBUs = ExpTotalesBUs.ToArray();}

    Hi Viorel..
    Thanks a lot for you help.
    I am absolutely sure that the second ítem of BU is valid and exist in the table because I tried to make a "Select" statement in the table providing the values of [Opportunity ID] and [BU] and I get the expected record. So, why is not
    working using Find() with the defined Primary Keys??? 
    I tried this in order to test that the record exists...
    if(RenglonInfo == null)
    string strSelect = "[Opportunity ID] = '0000218256' AND [BU] = 'SFW'";
    RenglonInfo2 = TablaFunnel.Tabla.Select(strSelect);

  • C#: Sending email from a specific account when multiple accounts exist in Outlook?

    Somehow I accidentally deleted this message trying to edit it... sorry.
    Microsoft.Office.Interop.Outlook.Application outApp = null;
    outApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
    MailItem mailItem = (MailItem)outApp.CreateItem(OlItemType.olMailItem);
    mailItem.Subject = "Director Script Confirmation Request";
    mailItem.To = person;
    mailItem.Body = message;
    //mailItem.Display(false);
    mailItem.Send();
    How do I send email from a specific account when multiple accounts exist in Outlook?
    Below is the code that I have. I think I'm supposed to use the AddressEntry or AddressEntries to designate where emails are sent from. However, at the moment, I haven't found an example.
    SV

    Hello SV,
    The MailItem class provides the
    SendUsingAccount property which allows to set an Account object
    that represents the account under which the MailItem is
    to be sent. Here is what MSDN states:
    The SendUsingAccount property can be used to specify the account
    that should be used to send the MailItem when the Send method
    is called.
    Sub SendUsingAccount()
    Dim oAccount As Outlook.account
    For Each oAccount In Application.Session.Accounts
    If oAccount.AccountType = olPop3 Then
    Dim oMail As Outlook.MailItem
    Set oMail = Application.CreateItem(olMailItem)
    oMail.Subject = "Sent using POP3 Account"
    oMail.Recipients.Add ("[email protected]")
    oMail.Recipients.ResolveAll
    oMail.SendUsingAccount = oAccount
    oMail.Send
    End If
    Next
    End Sub

Maybe you are looking for