Expport latest n records

Hi All,
How to export latest n records from a table using the below query(latest n records)
select * from (select empid,ename,sal,joining_date from emp order by joining_date desc) where rownum<n;
Thanks

Technohub wrote:
Hi All,
How to export latest n records from a table using the below query(latest n records)
select * from (select empid,ename,sal,joining_date from emp order by joining_date desc) where rownum<n;
ThanksWhat is the DB & OS version?
Example:-
$exp scott/tiger TABLES=employees QUERY=\"WHERE dept=<n>\"

Similar Messages

  • Find the latest updated or the latest inserted record  in a table

    Hi All,
    Thanks in advance
    Just a simple question
    How do we find the latest updated or the latest inserted record in a table ?
    Provide some queries in SQL?

    You can order by rowid desc to get lately inserted records, but I'm not sure about updated records.That is incorrect, Oracle might use old rowid's even in inserts and you cannot assure that the max(rowid) refers to the latest record.
    If the table is created with rowdependencies one can use ORA_ROWSCN pseudo column to check on date/time when the last dml has been performed over that table. But, that has some limitations too, Old snapshots will be erased hence one can check the last dml with a time frame of few days.
    Regards,
    Prazy

  • Get the latest date record in Query

    Hi, Expert:
    Please help on this:
    The requirement is to get the the latest date record in Query. For example:
    Data in provider:
    Plant          date            amount
    A01         2007/04/08      30
    A01         2007/06/09      70
    A01         2007/12/08      30
    we only want the query display:
    A01         2007/12/08      30
    I have tried exception aggregation, but it does not work. Any ideas are highly appreciated.

    Or you can model the date as a key figure after 0date_kyf and set aggregation to max, you'll get something like
    select plant, amount, max(date) from ... group by plant, amount
    used it for inventory reporting (materials and their last movement date, days from the last movement etc.) and worked well.

  • Latest Updated Record in OBIEE

    How to get only latest Updated Record in OBIEE answers
    Thanks&regards
    cnu

    HI,
    agg function last doesn't help?
    If not, create a new column upd_date in your database table and with triggers update it with sysdate.
    Add it in repository, map it with max() function and then filter your data where upd_date = that max() column...
    Or in presentation create an report that uses only that max() column and your report filter based on other report (that report)...
    Haven't tried but I think it will work....
    Hope It helps...
    Regards
    Nicolae

  • Fetching latest active records

    Hi,
    I have a scenario to take only the latest date record for each key column value (ID column). But the latest segment should not be a deleted one. Hereby i am providing an example of my input details and required output values. Thanks in advance!
    Type O = Created
    Type R = Updated
    Type S = Deleted
    CREATE TABLE #T (ID VARCHAR(16), SEGMENT INT, STYPE VARCHAR(1), Eff_dt Date)
    INSERT INTO #T VALUES ('101',1,'O','2013-07-01')
    INSERT INTO #T VALUES ('101',1,'S','2013-07-01')
    INSERT INTO #T VALUES ('102',1,'O','2013-06-15')
    INSERT INTO #T VALUES ('102',1,'S','2013-06-15')
    INSERT INTO #T VALUES ('102',2,'O','2013-06-19')
    INSERT INTO #T VALUES ('102',2,'R','2013-06-20')
    INSERT INTO #T VALUES ('103',1,'O','2013-01-01')
    INSERT INTO #T VALUES ('103',1,'R','2013-01-06')
    INSERT INTO #T VALUES ('103',1,'R','2013-11-23')
    SELECT * FROM #T
    DROP TABLE #T
    In the above example, the output should be
    1.) The ID '101' should be ignored as it is created and deleted on the same date (which is latest date for ID 101)
    2.) The ID '102' , Segment 2 value should be come as output, because Segment 1 is deleted earlier and segment 2 is created and updated recently.
    3.) The ID '103' for 2013-11-23 should be come as this is the latest one and its not deleted.
    I am attaching the expected output for my requirement.
    Regards,
    Fazlu

    Hi,
    Thanks for your reply. But its not corrct for my scenario. As i said, ID '101' should not come in output as it is Created and Deleted on same day, I also tried your query, but it s fetching 101, which is not correct one for my situation.
    If we took max day for each ID, 101 will have 2 values, which is both open and closed record, if same Segment is open and closed on same day, i should not consider that ID at all.
    Regards,
    Fazlu
    Ok
    what about this?
    SELECT ID,SEGMENT,STYPE,Eff_dt
    FROM
    SELECT *,
    DENSE_RANK() OVER (PARTITION BY ID ORDER BY Eff_dt DESC) AS Seq
    FROM #T
    )t
    WHERE Seq = 1
    GROUP BY ID,SEGMENT,STYPE,Eff_dt
    HAVING SUM(CASE WHEN STYPE = 'S' THEN 1 ELSE 0 END)=0
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • EJB-QL Latest 10 records

    How can i write an EJB-QL which can fetch latest 10 records on basis of a date field??
    my entity bean has a date field and i want latest 10 records
    any idea ??
    thanx

    i think this will work
    select emp1.dob from emp emp1 where 10 < ( select count(*) from emp
    emp2 where emp1.dob>emp2.dob) order by emp1.dob asc
    for date comparision plz check this link also,
    http://download-west.oracle.com/otn_hosted_doc/jdeveloper/904preview/developing_ejb/ejb_pfindermethod.html
    renjith.

  • How to delete the duplicate rows present in the parent table & insert the latest duplicate record into the parent table linked with the child table.

    I have a master table and i need to import the rows into the parent and child table.
    Master table name is Flatfile_Inventory
    Parent Table name is INVENTORY
    Child Tables name are INVENTORY_AMOUNT,INVENTORY_DETAILS,INVENTORY_VEHICLE,
    Error details will be goes to LOG_INVENTORY_ERROR
    I have 4 duplicate rows in the Flatfile_Inventory which i have already inserted in the Parent and child table.
    Again when i run the query using stored procedure,
    its tells that all the 4 rows are duplicate and will move to the Log_Inventory_Error.
    I need is if i have the duplicate rows in the flatfile_Inventory when i start inserting into the parent and child table the already inserted row have the unique ID i
    must identify it and delete that row in the both parent and chlid table.And latest row must get inserted into the Parent and child table from Flatfile_Inventory.
    Please help me to write the query i have attached the Full stored procedure Script..
    Arunraj Kumar

    Hi Santhosh,
    This is my Script.
    -- =============================================
    -- Stored Procedure for FLATFILE_INVENTORY
    -- =============================================
    -- Drop stored procedure if it already exists
       DROP PROCEDURE SP_Flatfile_Inventory
    GO
    CREATE PROCEDURE SP_Flatfile_Inventory
    AS
    --USE IconicMarketing
    GO
    DECLARE
    @FileType  varchar(50)  ,
    @ACDealerID  varchar(50)  ,
    @ClientDealerID  varchar(50)  ,
    @DMSType  varchar(50)  ,
    @StockNumber  varchar(50)  ,
    @InventoryDate  datetime  ,
    @StockType  varchar(100)  ,
    @DMSStatus  varchar(50)  ,
    @InvoicePrice  numeric(18, 2)  ,
    @CostPack  varchar(50)  ,
    @SalesCost  numeric(18, 2)  ,
    @HoldbackAmount  numeric(18, 2)  ,
    @ListPrice  numeric(18, 2)  ,
    @MSRP  varchar(max)  ,
    @LotLocation  varchar(50)  ,
    @TagLine  varchar(max)  ,
    @Certification  varchar(max)  ,
    @CertificationNumber  varchar(max)  ,
    @VehicleVIN  varchar(50)  ,
    @VehicleYear  bigint  ,
    @VehicleMake  varchar(50)  ,
    @VehicleModel  varchar(50)  ,
    @VehicleModelCode  varchar(50)  ,
    @VehicleTrim  varchar(50)  ,
    @VehicleSubTrimLevel  varchar(max)  ,
    @Classification  varchar(max)  ,
    @TypeCode  varchar(100)  ,
    @VehicleMileage  bigint  ,
    @EngineCylinderCount  bigint  ,
    @TransmissionType  varchar(50)  ,
    @VehicleExteriorColor  varchar(50)  ,
    @VehicleInteriorColor  varchar(50)  ,
    @CreatedDate  datetime  ,
    @LastModifiedDate  datetime  ,
    @ModifiedFlag  varchar(max)  ,
    @InteriorColorCode  varchar(50)  ,
    @ExteriorColorCode  varchar(50)  ,
    @PackageCode  varchar(50)  ,
    @CodedCost  varchar(50)  ,
    @Air  varchar(100)  ,
    @OrderType  varchar(max)  ,
    @AgeDays  bigint  ,
    @OutstandingRO  varchar(50)  ,
    @DlrAccessoryRetail  varchar(50)  ,
    @DlrAccessoryCost  varchar(max)  ,
    @DlrAccessoryDesc  varchar(max)  ,
    @ModelDesc  varchar(50)  ,
    @Memo1  varchar(1000)  ,
    @Memo2  varchar(max)  ,
    @Weight  varchar(max)  ,
    @FloorPlan  numeric(18, 2)  ,
    @Purchaser  varchar(max)  ,
    @PurchasedFrom  varchar(max)  ,
    @InternetPrice  varchar(50)  ,
    @InventoryAcctDollar  numeric(18, 2)  ,
    @VehicleType  varchar(50)  ,
    @DealerAccessoryCode  varchar(50)  ,
    @AllInventoryAcctDollar  numeric(18, 2)  ,
    @BestPrice  varchar(50)  ,
    @InStock  bigint  ,
    @AccountingMake  varchar(50)  ,
    @GasDiesel  varchar(max)  ,
    @BookValue  varchar(10)  ,
    @FactoryAccessoryDescription  varchar(max)  ,
    @TotalReturn  varchar(10)  ,
    @TotalCost  varchar(10)  ,
    @SS  varchar(max)  ,
    @VehicleBody  varchar(max)  ,
    @StandardEquipment  varchar(max)  ,
    @Account  varchar(max)  ,
    @CalculatedPrice  varchar(10)  ,
    @OriginalCost  varchar(10)  ,
    @AccessoryCore  varchar(10)  ,
    @OtherDollar  varchar(10)  ,
    @PrimaryBookValue  varchar(10)  ,
    @AmountDue  varchar(10)  ,
    @LicenseFee  varchar(10)  ,
    @ICompany  varchar(max)  ,
    @InvenAcct  varchar(max)  ,
    @Field23  varchar(max)  ,
    @Field24  varchar(max)  ,
    @SalesCode  varchar(max)  ,
    @BaseRetail  varchar(10)  ,
    @BaseInvAmt  varchar(10)  ,
    @CommPrice  varchar(10)  ,
    @Price1  varchar(10)  ,
    @Price2  varchar(10)  ,
    @StickerPrice  varchar(10)  ,
    @TotInvAmt  varchar(10)  ,
    @OptRetail  varchar(max)  ,
    @OptInvAmt  varchar(10)  ,
    @OptCost  varchar(10)  ,
    @Options  varchar(max)  ,
    @Category  varchar(max)  ,
    @Description  varchar(max)  ,
    @Engine  varchar(max)  ,
    @ModelType  varchar(max)  ,
    @FTCode  varchar(max)  ,
    @Wholesale  varchar(max)  ,
    @Retail  varchar(max)  ,
    @Draft  varchar(max)  ,
    @Inventoryid int;
    DECLARE Inventory_Cursor CURSOR FOR 
    SELECT * from [dbo].[FLATFILE_INVENTORY];
    OPEN Inventory_Cursor
    FETCH NEXT FROM Inventory_Cursor 
    INTO @FileType   ,
    @ACDealerID     ,
    @ClientDealerID     ,
    @DMSType     ,
    @StockNumber     ,
    @InventoryDate    ,
    @StockType    ,
    @DMSStatus     ,
    @InvoicePrice     ,
    @CostPack     ,
    @SalesCost     ,
    @HoldbackAmount     ,
    @ListPrice     ,
    @MSRP     ,
    @LotLocation     ,
    @TagLine     ,
    @Certification     ,
    @CertificationNumber     ,
    @VehicleVIN     ,
    @VehicleYear     ,
    @VehicleMake     ,
    @VehicleModel     ,
    @VehicleModelCode     ,
    @VehicleTrim     ,
    @VehicleSubTrimLevel     ,
    @Classification     ,
    @TypeCode    ,
    @VehicleMileage     ,
    @EngineCylinderCount     ,
    @TransmissionType     ,
    @VehicleExteriorColor     ,
    @VehicleInteriorColor     ,
    @CreatedDate    ,
    @LastModifiedDate    ,
    @ModifiedFlag     ,
    @InteriorColorCode     ,
    @ExteriorColorCode     ,
    @PackageCode     ,
    @CodedCost     ,
    @Air    ,
    @OrderType     ,
    @AgeDays     ,
    @OutstandingRO     ,
    @DlrAccessoryRetail     ,
    @DlrAccessoryCost     ,
    @DlrAccessoryDesc     ,
    @ModelDesc     ,
    @Memo1 ,
    @Memo2     ,
    @Weight     ,
    @FloorPlan     ,
    @Purchaser     ,
    @PurchasedFrom     ,
    @InternetPrice     ,
    @InventoryAcctDollar     ,
    @VehicleType     ,
    @DealerAccessoryCode     ,
    @AllInventoryAcctDollar     ,
    @BestPrice     ,
    @InStock     ,
    @AccountingMake     ,
    @GasDiesel     ,
    @BookValue     ,
    @FactoryAccessoryDescription     ,
    @TotalReturn     ,
    @TotalCost     ,
    @SS     ,
    @VehicleBody     ,
    @StandardEquipment     ,
    @Account     ,
    @CalculatedPrice     ,
    @OriginalCost     ,
    @AccessoryCore     ,
    @OtherDollar     ,
    @PrimaryBookValue     ,
    @AmountDue     ,
    @LicenseFee     ,
    @ICompany     ,
    @InvenAcct     ,
    @Field23     ,
    @Field24     ,
    @SalesCode     ,
    @BaseRetail     ,
    @BaseInvAmt     ,
    @CommPrice     ,
    @Price1     ,
    @Price2     ,
    @StickerPrice     ,
    @TotInvAmt     ,
    @OptRetail     ,
    @OptInvAmt     ,
    @OptCost     ,
    @Options     ,
    @Category     ,
    @Description     ,
    @Engine     ,
    @ModelType     ,
    @FTCode     ,
    @Wholesale     ,
    @Retail     ,
    @Draft     ;
    WHILE @@FETCH_STATUS = 0
    BEGIN
        PRINT @VehicleVIN    ;
    -- ****************** insert into Inventory Table ***********
    INSERT INTO INVENTORY 
    IconicDealerID,
    StockNumber,
    DMSType,
    InventoryDate
    VALUES (@ClientDealerID,@StockNumber,@DMSType,@InventoryDate);
    set @Inventoryid = scope_identity();
    PRINT @Inventoryid;
    --Insert into Inventory_Details Table
    INSERT INTO [INVENTORY_DETAILS]
    InventoryID,
    StockType,
    DMSStatus,
    LotLocation,
    TagLine,
    Certification,
    CertificationNumber,
    CreatedDate,
    LastModifiedDate,
    ModifiedFlag,
    PackageCode,
    OrderType,
    AgeDays,
    OutstandingRO,
    Memo1,
    Memo2,
    Purchaser,
    PurchasedFrom,
    DealerAccessoryCode,
    InStock,
    AccountingMake,
    SS,
    Account,
    AccessoryCore,
    ICompany,
    InvenAcct,
    Field23,
    Field24,
    SalesCode,
    Draft,
    FTCode
    VALUES (
    @InventoryID,
    @StockType,
    @DMSStatus,
    @LotLocation,
    @TagLine,
    @Certification,
    @CertificationNumber,
    @CreatedDate,
    @LastModifiedDate,
    @ModifiedFlag,
    @PackageCode,
    @OrderType,
    @AgeDays,
    @OutstandingRO,
    @Memo1,
    @Memo2,
    @Purchaser,
    @PurchasedFrom,
    @DealerAccessoryCode,
    @InStock,
    @AccountingMake,
    @SS,
    @Account,
    @AccessoryCore,
    @ICompany,
    @InvenAcct,
    @Field23,
    @Field24,
    @SalesCode,
    @Draft,
    @FTCode
    --Insert into Inventory_Amount Table
    INSERT INTO [dbo].[INVENTORY_AMOUNT]
    InventoryID,
    AllInventoryAcctDollar,
    OtherDollar,
    PrimaryBookValue,
    AmountDue,
    LicenseFee,
    CalculatedPrice,
    OriginalCost,
    BookValue,
    TotalReturn,
    TotalCost,
    DlrAccessoryRetail,
    DlrAccessoryCost,
    DlrAccessoryDesc,
    InternetPrice,
    InventoryAcctDollar,
    BestPrice,
    Weight,
    FloorPlan,
    CodedCost,
    InvoicePrice,
    CostPack,
    SalesCost,
    HoldbackAmount,
    ListPrice,
    MSRP,
    BaseRetail,
    BaseInvAmt,
    CommPrice,
    Price1,
    Price2,
    StickerPrice,
    TotInvAmt,
    OptRetail,
    OptInvAmt,
    OptCost,
    Wholesale,
    Retail
    VALUES (
    @InventoryID,
    @AllInventoryAcctDollar,
    @OtherDollar,
    @PrimaryBookValue,
    @AmountDue,
    @LicenseFee,
    @CalculatedPrice,
    @OriginalCost,
    @BookValue,
    @TotalReturn,
    @TotalCost,
    @DlrAccessoryRetail,
    @DlrAccessoryCost,
    @DlrAccessoryDesc,
    @InternetPrice,
    @InventoryAcctDollar,
    @BestPrice,
    @Weight,
    @FloorPlan,
    @CodedCost,
    @InvoicePrice,
    @CostPack,
    @SalesCost,
    @HoldbackAmount,
    @ListPrice,
    @MSRP,
    @BaseRetail,
    @BaseInvAmt,
    @CommPrice,
    @Price1,
    @Price2,
    @StickerPrice,
    @TotInvAmt,
    @OptRetail,
    @OptInvAmt,
    @OptCost,
    @Wholesale,
    @Retail
    --Insert into Inventory_Vehicle Table
    INSERT INTO [dbo].[INVENTORY_VEHICLE]
    InventoryID,
    InteriorColorCode,
    ExteriorColorCode,
    Air,
    ModelDesc,
    VehicleType,
    VehicleVIN,
    VehicleYear,
    VehicleMake,
    VehicleModel,
    VehicleModelCode,
    VehicleTrim,
    VehicleSubTrimLevel,
    Classification,
    TypeCode,
    VehicleMileage
    VALUES (
    @InventoryID,
    @InteriorColorCode,
    @ExteriorColorCode,
    @Air,
    @ModelDesc,
    @VehicleType,
    @VehicleVIN,
    @VehicleYear,
    @VehicleMake,
    @VehicleModel,
    @VehicleModelCode,
    @VehicleTrim,
    @VehicleSubTrimLevel,
    @Classification,
    @TypeCode,
    @VehicleMileage
    -- Move cursor to Next record 
        FETCH NEXT FROM Inventory_Cursor 
    INTO @FileType   ,
    @ACDealerID     ,
    @ClientDealerID     ,
    @DMSType     ,
    @StockNumber     ,
    @InventoryDate    ,
    @StockType    ,
    @DMSStatus     ,
    @InvoicePrice     ,
    @CostPack     ,
    @SalesCost     ,
    @HoldbackAmount     ,
    @ListPrice     ,
    @MSRP     ,
    @LotLocation     ,
    @TagLine     ,
    @Certification     ,
    @CertificationNumber     ,
    @VehicleVIN     ,
    @VehicleYear     ,
    @VehicleMake     ,
    @VehicleModel     ,
    @VehicleModelCode     ,
    @VehicleTrim     ,
    @VehicleSubTrimLevel     ,
    @Classification     ,
    @TypeCode    ,
    @VehicleMileage     ,
    @EngineCylinderCount     ,
    @TransmissionType     ,
    @VehicleExteriorColor     ,
    @VehicleInteriorColor     ,
    @CreatedDate    ,
    @LastModifiedDate    ,
    @ModifiedFlag     ,
    @InteriorColorCode     ,
    @ExteriorColorCode     ,
    @PackageCode     ,
    @CodedCost     ,
    @Air    ,
    @OrderType     ,
    @AgeDays     ,
    @OutstandingRO     ,
    @DlrAccessoryRetail     ,
    @DlrAccessoryCost     ,
    @DlrAccessoryDesc     ,
    @ModelDesc     ,
    @Memo1 ,
    @Memo2     ,
    @Weight     ,
    @FloorPlan     ,
    @Purchaser     ,
    @PurchasedFrom     ,
    @InternetPrice     ,
    @InventoryAcctDollar     ,
    @VehicleType     ,
    @DealerAccessoryCode     ,
    @AllInventoryAcctDollar     ,
    @BestPrice     ,
    @InStock     ,
    @AccountingMake     ,
    @GasDiesel     ,
    @BookValue     ,
    @FactoryAccessoryDescription     ,
    @TotalReturn     ,
    @TotalCost     ,
    @SS     ,
    @VehicleBody     ,
    @StandardEquipment     ,
    @Account     ,
    @CalculatedPrice     ,
    @OriginalCost     ,
    @AccessoryCore     ,
    @OtherDollar     ,
    @PrimaryBookValue     ,
    @AmountDue     ,
    @LicenseFee     ,
    @ICompany     ,
    @InvenAcct     ,
    @Field23     ,
    @Field24     ,
    @SalesCode     ,
    @BaseRetail     ,
    @BaseInvAmt     ,
    @CommPrice     ,
    @Price1     ,
    @Price2     ,
    @StickerPrice     ,
    @TotInvAmt     ,
    @OptRetail     ,
    @OptInvAmt     ,
    @OptCost     ,
    @Options     ,
    @Category     ,
    @Description     ,
    @Engine     ,
    @ModelType     ,
    @FTCode     ,
    @Wholesale     ,
    @Retail     ,
    @Draft     ;
    END 
    CLOSE Inventory_Cursor;
    DEALLOCATE Inventory_Cursor;
    GO
    SET ANSI_PADDING OFF
    GO
    Arunraj Kumar

  • Making system to use the latest Infotype Record for the Current Period

    Hello,
    I would like to know how the system behave if there is a record modified in the middle of the Pay Period, which record would the PY schema use? Ex: in IT0009 EE has selected multiple Bank Transfer. He say 100$ Bank 1 and Rest to Bank 2. In the middle if the Pay period, the EE comes and makes changes to his Bank Transfer, as he closed the account in Bank1, he creates new Bank and transfers 100$. Now when the PY run, it think both Banks (Bank1 prev and Bank 1 current ) are valid and tries to send 100$ to each back and sends rest to Bank2. Which is not correct. This issue happens when someone changes their record in the middle of the period. So It is assumed to change the process to not to change in the middle of the period. It has to be effecting of 1st of next period.
    But I want to check is there anyway we can make the system to use the latest one if it finds multiple record for the same period?
    any suggestion please.
    Thank you.
    Raj

    Hi Donnie,
    This system actually delimits the previous record but since the change is happened in the middle of the period, but record are considered as active.
    For Ex: The Pay Period is 01/01/2009 to 01/15/2009 and There was a record for Bank1 for that period and user comes and creates a new record on 01/05/2009 for Bank1. Now for this payperiod since its with the period both records are becoming active. So system uses both the records and deducts. Hope you get what I'm saying.
    Thanks,
    Raj

  • Report the latest  event (record) for a device

    I could have sworn I had this one working before but for the life of me I cant remember how I did it and I cant seem to figure it out anew.
    I'm tracking events per device. A device may have any number of events in a given time period. I need to track the MOST RECENT event for a device per device. I do not want to have multiple records per device, only the record with the MOST RECENT timestamp.
    I made the following two attempts but I'm still getting nowhere.
    select
      device,
      MAX(dt) KEEP (DENSE_RANK FIRST ORDER BY dt) as time_Var
    from db_table partition (pPname)
    where
        Lower(example) like '%example text%'
        and dt > sysdate - 5and
    select DISTINCT
    device,
           (select TO_CHAR( (MAX(table_name.dt)), 'HH24:MI:SS MM/DD/YYYY') "timeVar"
              from table_name partition (pPName)
              where
           Lower(Example) like '%example text%'
           and dt > sysdate - 5)
    from table_name partition (pPName)
    where
        Lower(Example) like '%example text%'
        and dt > sysdate - 5
    order by device Asc;

    Hi,
    Salim's solution with
    KEEP (DENSE_RANK FIRST ORDER BY dt)will show you the least recent event in the last 5 days.
    If you want the most recent event, change "FIRST" to "LAST"
    KEEP (DENSE_RANK LAST ORDER BY dt)or sort in DESCending order:
    KEEP (DENSE_RANK FIRST ORDER BY dt DESC)If you want to display several columns from the most recent row, you'll have to use KEEP (DENSE_RANK ...) on each of them (except device).
    In that case, you might find it easier to use an analytic function, such as ROW_NUMBER:
    WITH     ranked_data  AS
         SELECT     device, column_a, column_b, column_c
         ,     ROW_NUMBER () OVER ( PARTITION BY  device
                                   ORDER BY          dt     DESC
                           )  AS r_num
         FROM     your_table
         WHERE     LOWER (example)      LIKE '%example text%'
         AND     dt               > SYSDATE - 5
    SELECT  device, column_a, column_b, column_c
    FROM     ranked_data
    WHERE     r_num   = 1;

  • Problem in fetching the latest updated record.

    Hello ,
    I have  a program in which i am creating a BDC session and submit the same in program rsbdcsub, now the problem is that i need to capture the Field Qstate from the table APQI, its not updated instantaneously, so i am not able to get the latest value of QSTATE from updated APQI table,
    I have used commit work, commit work and wait , SET UPDATE TASK LOCAL, nothing is working, only if i put wait up to '1.5' seconds before fetching the value from table APQI i get the updated Qstate, but this will create a performance issue so please suggest.
    Can any one please help me resolve this problem.
    Regards,
    Abhinav

    it's quite normal that status is updated after the job is modified
    and you cannot know beforehand how much time it will take to do it (even the start time is not sure because it could be delayed !)
    you could select the value until it is one of a list that you expect (for example, finished or cancelled)

  • Varchar to Datetime conversion and selecting latest datead records

    Hi:
    I've a table as below:
    ActionDate|Status|Name
    23/10/2012|Block|James
    24/10/2012|Open|James
    25/10/2012|Block|James
    20/09/2012|Block|Tanya
    17/09/2012|Block|Fox
    18/09/2012|Open|Fox
    27/08/2012|Block|Martin
    27/08/2012|Open|Martin
    Desired Output is as follows:
    ActionDate|Status|Name
    25/10/2012|Block|James
    20/09/2012|Block|Tanya
    Select those records only which has Block staus on most recent date. It will also eliminate those which has Open status on the same date.
    One more problem is the ActionDate field is actually Varchar2 type and there are mismatch as well. For example: some of those are in MM/DD/YYYY and
    some are in DD/MM/YYYY
    So, how can I convert these strings into formated date and make the desired output in a single query. Please let me know.
    Thanks/Tanvir

    Hi, Tanvir,
    853856 wrote:
    Hi:
    I've a table as below:
    ActionDate|Status|Name
    23/10/2012|Block|James
    24/10/2012|Open|James
    25/10/2012|Block|James
    20/09/2012|Block|Tanya
    17/09/2012|Block|Fox
    18/09/2012|Open|Fox
    27/08/2012|Block|Martin
    27/08/2012|Open|MartinWhenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data.
    Desired Output is as follows:
    ActionDate|Status|Name
    25/10/2012|Block|James
    20/09/2012|Block|TanyaSee the forum FAQ {message:id=9360002} for how to format the ouptut on this site (among other things).
    Select those records only which has Block staus on most recent date. It will also eliminate those which has Open status on the same date.
    One more problem is the ActionDate field is actually Varchar2 type That's not a very good idea. This problem shows just one of the many reasons why you should always use DATE columns for date information.
    and there are mismatch as well. For example: some of those are in MM/DD/YYYY and
    some are in DD/MM/YYYYThe you have no way of knowing if '01/12/2012' means January 12 or December 1. The query below arbitrarily assumes that will be December 1.
    So, how can I convert these strings into formated date and make the desired output in a single query. Please let me know.
    Thanks/TanvirHere's one way:
    WITH     got_real_actiondate     AS
         SELECT     TO_DATE ( actiondate
                   , CASE
                             WHEN  SUBSTR (actiondate, 4, 2)     <= '12'
                         THEN  'MM/DD/YYYY'
                         ELSE  'DD/MM/YYYY'
                     END
                   )     AS real_actiondate
         ,     status
         ,     name
         FROM     a_table
    ,     got_r_num     AS
         SELECT     real_actiondate
         ,     status
         ,     name
         ,     ROW_NUMBER () OVER ( PARTITION BY  name
                                   ORDER BY          real_actindate     DESC
                             ,                CASE
                                              WHEN  status = 'Open'
                                         THEN  1
                                         ELSE  2
                                          END
                           ) AS r_num
         FROM    got_real_actiondate
    SELECT     real_actiondate
    ,     status
    ,     name
    FROM     got_r_num
    WHERE     r_num     = 1
    AND     status     != 'Open'
    ;This assumes that actiondate is in either 'DD/MM/YYYY' or 'MM/DD/YYYY' format, which is very optimistic. If you sometimes have other formats as well, and/or text that can't be interpreted as a date in any format, then see {message:id=4252963}
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as INSERT) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Select latest two records per group

    hi there,
    i've been googling around and still can't really find an appropriate solution to retrieve two most recent records per group in one sql. Is this even possible?
    Let's say there is a MyLife table :
    ID, Event , RecordedDate
    1. 1, 'Fell down the stairs', '20-DEC-07'
    2. 1, 'Fell down the stairs', '22-DEC-07'
    3. 1, 'Fell down the stairs', '23-DEC-07'
    4. 2, 'Tried to kiss santa', '23-DEC-07'
    5. 3, 'Reindeer stolen', '24-DEC-07'
    6. 4, 'Chimney Broke', '25-DEC-07'
    Output should be :
    2. 1, 'Fell down the stairs', '22-DEC-07'
    3. 1, 'Fell down the stairs', '23-DEC-07'
    4. 2, 'Tried to kiss santa', '23-DEC-07'
    5. 3, 'Reindeer stolen', '24-DEC-07'
    6. 4, 'Chimney Broke', '25-DEC-07'

    I believe that something along these lines would be portable to most other databases.
    SQL> SELECT id, event, recordeddate
      2  FROM mylife o
      3  WHERE recordeddate = (SELECT MAX(recordeddate) FROM mylife i
      4                        WHERE o.id = i.id)
      5  UNION ALL
      6  SELECT id, event, recordeddate
      7  FROM mylife o
      8  WHERE recordeddate = (SELECT MAX(recordeddate) FROM mylife i
      9                        WHERE o.id = i.id and
    10                              i.recordeddate < (SELECT MAX(recordeddate)
    11                                                FROM mylife ii
    12                                                WHERE i.id = ii.id))
    13  ORDER BY id, recordeddate;
            ID EVENT                     RECORDEDDAT
             1 Fell down the stairs      22-DEC-2007
             1 Fell down the stairs      23-DEC-2007
             2 Tried to kiss santa       23-DEC-2007
             3 Reindeer stolen           24-DEC-2007
             4 Chimney Broke             25-DEC-2007John

  • How to get the latest ALV record?

    Hi all,
    I have create a ALV in my module pool with delete row feature. The module pool is able to display the record into the ALV.
    The user needs to delete some of the unwanted records. After that, my program needs to populate the record (after deleted rows), and save it into a customized table.
    My question is, how can I get the most up-to-date record from the ALV and assign it into internal table?
    Thanks in advance.

    Hi,
    Yes, I am using OOPs ALV
    I have included this code into PAI, but how do I get it assigns to a internal table?
    data: lv_valid type c,
          lv_refresh type c.
    call method grid1->check_changed_data
      importing
        e_valid = lv_valid
      changing
        c_refresh = lv_refresh.
    PBO
      data  grid1 type ref to cl_gui_alv_grid.
      call method grid1->set_table_for_first_display
        exporting
          i_structure_name     = 'ZSTRUCTURE_EXCEL'
          it_toolbar_excluding = lt_exclude
          is_layout            = ls_layout
        changing
          it_outtab            = gt_export2excel.
    FYI, my ALV is with delete row feature, the user will delete some of the row and now I need to get the remaining row and assign it to an internal table.
    Please help with some sample code. Thanks.

  • Source list supplier and latest Infor Record price

    Hi,
    Which SAP code can use to run the report to list display for parts current source list supplier and most update info record price?
    Thanks
    Asini Yadaiah....

    Hi,
    Run following reports;
    ME0M - Source List per Material
    ME1M - Info Record per Material
    ME1L - Info Record per Vendor
    ME1P - PO Price History

  • Cross Join Records - only want the "latest valid" records depending on Shop-Level

    Hi everyone,
    I have a problem with the cross join for my retail application.
    Initial Situation:
    There are several Shops and in also several products. Usually the products are just created on global level so that all shops can access and sell them.
    BUT there is a feature, that single shops can create derivations of articles to change some settings for them (e.g. a the price of a certain handy is global 90€ but in one flagship store the price is 80€).
    Sample Tables
    create table shops(
    id number,
    name varchar2(64) not null,
    hierarchy varchar2(64) not null,
    parent number,
    PRIMARY KEY (id));
    create table articles(
    id number,
    name varchar2(64) not null,
    price number,
    shop_id number not null,
    PRIMARY KEY (id));
    -- create 4 shops with the hierarchy
    - Global
        |- Shop A
        |- Shop B
              |- Shop B.1
    insert into shops values (0, 'Global', '.0.', null);
    insert into shops values (1, 'Shop A', '.0.1.', 0);
    insert into shops values (2, 'Shop B', '.0.2.', 0);
    insert into shops values (3, 'Shop B.1', '.0.2.3.', 2);
    -- insert some articles + derive the 'Article 2' for shop B.1
    insert into articles values (0, 'Article 1', 100, 0);
    insert into articles values (1, 'Article 2', 90, 0);
    insert into articles values (2, 'Article 2', 80, 3); -- derive article 2 for the shop 2 and set price to 80 instead of 90
    Sample Statements
    -- restrict to 'Article 1' where no derivations exists
    select s.*, a.*
    from shops s, articles a
    where s.hierarchy like '%.' || a.shop_id || '.%' -- ensures that derivations only appear at the level of the shop and not for each shop
    and a.name = 'Article 1';
    The result gets the one article for each shop. So I have no problem to restrict to a shop id, and getting the article even if it's not created for that shop level.
    Shop ID
    Shop Name
    Hierarchy
    Parent
    Article ID
    Article Name
    Price
    Article Shop ID
    0
    Global
    .0.
    null
    0
    Article 1
    100
    0
    1
    Shop A
    .0.1.
    0
    0
    Article 1
    100
    0
    2
    Shop B
    .0.2.
    0
    0
    Article 1
    100
    0
    3
    Shop B.1
    .0.2.3.
    2
    0
    Article 1
    100
    0
    -- restrict to 'Article 2' where one derivation exists
    select s.*, a.*
    from shops s, articles a
    where s.hierarchy like '%.' || a.shop_id || '.%' -- ensures that derivations only appear at the level of the shop and not for each shop
    and a.name = 'Article 2';
    The result of this statement shows, that the "Article 2" is contained two times for the ShopID 3. This is because the Article exists two times in the articles table.
    Shop ID
    Shop Name
    Hierarchy
    Parent
    Article ID
    Article Name
    Price
    Article Shop ID
    0
    Global
    .0.
    null
    1
    Article 2
    90
    0
    1
    Shop A
    .0.1.
    0
    1
    Article 2
    90
    0
    2
    Shop B
    .0.2.
    0
    1
    Article 2
    90
    0
    3
    Shop B.1
    .0.2.3.
    2
    1
    Article 2
    90
    0
    3
    Shop B.1
    .0.2.3.
    2
    2
    Article 2
    80
    3
    Problem1
    The last result shows my problem very well. I just want to get the highest level of article if there are any derivations.
    Problem2
    The solution must be very fast, because I have about
    3.000 Shops and about
    700.000 different Articles (on global level)
    Can somebody help my to find a performant solution for my problem?

    Hi,
    In the output for 'Article 2', do you really want prices of 100 and 65?  I assume you meant 90 and 80, like this:
                                                               ARTICLE
    SHOP SHOP                         ARTICLE ARTICLE          _SHOP
    _ID _NAME      HIERARCHY  PARENT _ID     _NAME      PRICE _ID
       0 Global     .0.               1       2          90    0
       1 Shop A     .0.1.           0 1       2          90    0
       2 Shop B     .0.2.           0 1       2          90    0
       3 Shop B.1   .0.2.3.         2 2       2          80    3
    Here's how I got the output above:
    WITH   joined_data     AS
        SELECT    s.id      AS shop_id
        ,         s.name    AS shop_name
        ,         s.hierarchy
        ,         s.parent
        ,         a.id AS article_id
        ,         a.name AS article_name
        ,         a.price
        ,         a.shop_id AS article_shop_id
        FROM             shops     s
        LEFT OUTER JOIN  articles  a  ON   a.shop_id  = s.id
                                      AND  a.name     = 'Article 2'  -- or whatever
    SELECT    shop_id
    ,         shop_name
    ,         hierarchy
    ,         parent
    ,         REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (article_id, '/')
                            , '(\d+)/*$'
                            , 1, 1, NULL, 1
                            )    AS article_id
    ,         REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (article_name, '/')
                            , '(\d+)/*$'
                            , 1, 1, NULL, 1
                            )    AS article_name
    ,         REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (price, '/')
                            , '(\d+)/*$'
                            , 1, 1, NULL, 1
                            )    AS price
    ,         REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (article_shop_id, '/')
                            , '(\d+)/*$'
                            , 1, 1, NULL, 1
                            )    AS article_shop_id
    FROM      joined_data
    START WITH  parent IS NULL
    CONNECT BY  parent = PRIOR shop_id
    Like everything else in Oracle, it depends on your version.
    I used '/' as a delimiter, assuming that character never occurs in the article_name, article_id, price or shop_id.  If '/' can occur in any of those columns, you can use any other character as a delimiter.  You don't have to use the same delimiter for all 4 columns, but remember to use the same delimiter in REGEXP_SUBSTR that you use in its nested SYS_CONNECT_BY_PATH.
    Instead of doing 4 very similar REGEXP_SUBSTR (SYS_CONNECT_BY_PATH ... ) calls, you could do just 1, for article_id, and then join to the articles table to get the other columns.  I suspect that the way I posted above is faster.

Maybe you are looking for

  • MacBook no longer able to access Time Capsule

    I have a MacBook and a G4 hooked up (wirelessly and via Ethernet respectively)to a 802.11n TC, purchased in Nov/08. Both computers had been backing up faithfully but recently, the MacBook does not recognize the TC. When I run the Airport Utility, it

  • Phantom music that won't go away.

    Alright, for at least a month now I have had "phantom" unexplained music playing on my MacBook. I don't know where it came from or where it's coming from. It is there most of the time, but some times it will stop and then start again. Does ANYONE hav

  • Printing wirelessly with Windows Vista

    Alright I just got our Vista laptop successfully connected to the TC wireless network. Now I'm trying to print wirelessly with the Vista laptop, but when I go into "add printer" in the Vista control panel, it's unable to detect the printer. The print

  • UJBR transaction data restore shows no data

    Dear All, We did a transaction data backup on the PROD to restore in QA. The UJBR restoration of transaction data on QA shows as successful both in foreground and background modes. However, no data is seen on the models. When i checked the zipped fil

  • Multiple reports in SAP CR addon

    Hallo All, One of the standard system messages displaying in SAP crystal addon is "Multiple report views are not permitted". Anyway, for some of our customers is important to generate more than one reports and make some comparisons before print-outs.