Query for Identifying column changes

Hi Guys,
Need help in getting a query for my scenario.
I have 2 table Table A and Table B. Both have same columns and data type.
Table A:
Id  PersonId    Name      Code      Date
1    1000           John         M         2014-07-28
2    1001           Mary         B         2014-07-28
3    1002           Robin        R         2014-07-28
4    1003           Maxie        N         2014-07-28
Table B:
Id  PersonId    Name      Code      Date
1    1000           John                     2014-07-28
2    1001           Hary         S         2014-07-28
3    1002           Justin       Q         2012-07-28
4    1003           Maxie       P         2013-07-28
My situation is:
I need to compare both the tables and need to identify the rows that has a change in all columns, if all other columns are not changed and Code is changed to blank, i need to ignore that row.
The expected outcome is:
Id  PersonId    Name      Code      Date
2    1001           Hary         S         2014-07-28
3    1002           Justin       Q         2012-07-28
4    1003           Maxie       P         2013-07-28
Thanks Guys...

I found the solution in a easy way i guess...
select * from 
SELECT ID, PERSONID,NAME,
case when code is null then
    select a.code from tablea A where A.ID = B.ID
else
 a.code
end as Code,
DATE FROM TABLE B
MINUS
SELECT ID,PERSONID,NAME,CODE,DATE FROM TABLE A
What do you guys think...would it work for my scenario....
i am testing few scenarios looks like working.......

Similar Messages

  • Need help with query for converting columns to rows

    Hello,
    I know this is a very common question asked in the forum. I have searched regading this, i did find some threads, but i was not able to achieve what i require from the answers posted. So anybody please help me.
    I have a table which is having multiple columns as follows:
    Insert into table_1 (X,Y,Z,A,B,C,D,E,F,G,H,I) values (0,0,2,0,0,1,3,0,0,0,0,0);I want to convert the result into a two column, multiple rows i.e., I want the result as follows:
    Col1 Col2
    X      0
    Y     0
    Z      2
    A     0
    B     0
    C     1
    D     3
    E     0
    F     0
    G     0
    H     0
    I      0Please anybody help me in writing the query for this..

    Is this what you are expecting:
    SQL> WITH T AS
      2  (
      3  SELECT 0 X, 0 Y, 2 Z, 0 A, 0 B, 1 C, 3 D, 0 E, 0 F, 0 G, 0 H, 0 I FROM DUAL
      4  )
      5  SELECT  'X' col1, X col2 FROM T
      6  UNION ALL
      7  SELECT  'Y' col1, Y col2 FROM T
      8  UNION ALL
      9  SELECT  'Z' col1, Z col2 FROM T
    10  UNION ALL
    11  SELECT  'A' col1, A col2 FROM T
    12  UNION ALL
    13  SELECT  'B' col1, B col2 FROM T
    14  UNION ALL
    15  SELECT  'C' col1, C col2 FROM T
    16  UNION ALL
    17  SELECT  'D' col1, D col2 FROM T
    18  UNION ALL
    19  SELECT  'E' col1, E col2 FROM T
    20  UNION ALL
    21  SELECT  'F' col1, F col2 FROM T
    22  UNION ALL
    23  SELECT  'G' col1, G col2 FROM T
    24  UNION ALL
    25  SELECT  'H' col1, H col2 FROM T
    26  UNION ALL
    27  SELECT  'I' col1, I col2 FROM T
    28  /
    C       COL2                                                                   
    X          0                                                                   
    Y          0                                                                   
    Z          2                                                                   
    A          0                                                                   
    B          0                                                                   
    C          1                                                                   
    D          3                                                                   
    E          0                                                                   
    F          0                                                                   
    G          0                                                                   
    H          0                                                                   
    C       COL2                                                                   
    I          0                                                                   
    12 rows selected.

  • Performance of update query for single column vs multiple column

    Hi All,
    I could not find any answer for this, does it ever matter in terms of performance updating single column versus multiple column in a single update query.
    For eg. table consisting of 15 columns, what would be the difference in performance when one column is update in the single query against another update query where 15 columns are updated.
    Please do keep in mind my table columns in actually could be around 150+.
    Thanks for any information provided.

    If updated columns aren´t on where clause , then the only impact of 15 columns will be a increase on redo generation, and a possible chainning row.
    So since the redo is one of the things that have a large impact, the answer is yes.
    The performance will be slower.
    Regards
    Helio Dias.
    http://heliodias.com
    OCE SQL, OCP 9i

  • Update query for XMLTYPE column

    Hello everyone,
    I have inserted xml data into XMLTYPE column of my table,xml data is something like this
    <Data type="FYI">                         
    <ID xmlns="http://orcl.com">T-1-1</ID>
    <Category>FRAME</Category>
    <ProductID>1</ProductID>
    <Name xmlns="http://orcl.com">Frame </Name>
    <Type>BASIC</Type>
    <Code>INSTALL</Code>
    <NodeID>1</NodeID>
    </Data>
    Now i need to update the values inside the <Data> element,like
    ID == T-2-2
    Category == IFRAME
    ProductID == 1.1
    Name == IFRAME
    We are using oracle 10g R2.
    Please help me out how to update. It would be very thankfull for your valuble suggestions
    Thanks in advance

    <Services>
    <DataService type="FRLY">
    <ID xmlns="http://www.openapplications.org/oagis/9">T-1-1-FRLY</ID>
    <CategoryCode>FRAME</CategoryCode>
    <ProductOfferingID>1</ProductOfferingID>
    <Name xmlns="http://www.openapplications.org/oagis/9">Frame Relay</Name>
    <SubType>FRLY - BASIC</SubType>
    <ActionCode>INSTALL</ActionCode>
    <NodeID>1</NodeID>
    <Contract>
    <ID xmlns="http://www.openapplications.org/oagis/9" schemeName="Networx Universal">00000</ID>
    <Category name="Contract Type">U</Category>
    </Contract>
    <Contract>
    <Type xmlns="http://www.openapplications.org/oagis/9">Routine</Type>
    </Contract>
    <CustomerParty>
    <Location/>
    </CustomerParty>
    <ProvisioningStatus type="BillingSetup">
    <Description xmlns="http://www.openapplications.org/oagis/9">C</Description>
    </ProvisioningStatus>
    <MileStone>
    <ID xmlns="http://www.openapplications.org/oagis/9">CWD</ID>
    <Date>2007-01-29</Date>
    </MileStone>
    <ActivityStatus>
    <Code xmlns="http://www.openapplications.org/oagis/9" name="DueDate"/>
    <EffectiveDateTime xmlns="http://www.openapplications.org/oagis/9">2007-01-29T00:00:00Z</EffectiveDateTime>
    </ActivityStatus>
    <AssociatedIDs>
    <ID xmlns="http://www.openapplications.org/oagis/9">1</ID>
    </AssociatedIDs>
    <AssociatedIDs>
    <TemporaryID schemeName="OPKEY">34908</TemporaryID>
    </AssociatedIDs>
    <Location>
    <ID xmlns="http://www.openapplications.org/oagis/9">T-510092</ID>
    </Location>
    <OrderID>RequestID</OrderID>
    <Accessory>
    <ActionCode>ADD</ActionCode>
    <Description xmlns="http://www.openapplications.org/oagis/9">IBM ESERVER-XSERIES306</Description>
    <CategoryCode>5</CategoryCode>
    <InstallVendorParty>
    <Name xmlns="http://www.openapplications.org/oagis/9">MCI</Name>
    </InstallVendorParty>
    </Accessory>
    <Circuit>
    <ID xmlns="http://www.openapplications.org/oagis/9">T-1-1-FRLY</ID>
    <AssociatedIDs/>
    </Circuit>
    </DataService>
    </Services>
    This was my xml which i have inserted into DB for the column XMLTYPE.Now i need to update few values in this whole file like values of
    ID under<DataService>
    Name under <DataService>
    ID under <Contract>
    Description under <ProvisioningStatus>
    i was using the UPDATEXML query to update those it's saying i row updated but when i extract it says null.
    Please help me out to solve this problem.
    Thanks in advance.

  • NOTIFICATION QUERY FOR UDF COLUMN

    Dear experts,
    I want notification query for delivery should not be add without fill up the information in  machine number column (UDF Column- U_MCnumber)
    Please do needful.
    Thanks & Regards,
    Akshata

    Dear all,
    I have got query ...........
    If @object_type = '15'and @transaction_type= ('A')
    BEGIN
    If Exists (Select T0.DocEntry from ODLN T0 Inner Join DLN1 T1
    On T0.DocEntry=T1.DocEntry INNER JOIN OITM T3 ON T3.ItemCode = T1.ItemCode
    Where (T1.U_MCnumber Is Null and T3.ITMsgrpcod='119')
    And T0.DocEntry = @list_of_cols_val_tab_del  )
    BEGIN
    Select @error = -1,
    @error_message = 'Please fill up machine number!!!'
    End
    End
    Thanks & Regards,
    Akshata

  • Query for Price List changes

    Hi,
    I need a query to get a listing of all sales orders where the pricing has been changed from the approved price list.
    Also, a query to pull a list of changes to price tables that occurred in February, March, and June months of 2007.
    Can anyone help me with this?
    thanks,
    Ashwathy

    Hi,
    I agree with you, possible but not probable. In pricing, you can have prices for all items, for categories and for items. You can also have prices defined for a range of quantities in a UOM. Assuming your prices are defined in the list for items, in the same UOM product was ordered, the query would be like that for one order:
    select c.ordered_item, c.unit_list_price, c.unit_selling_price, a.operand
    from qp_list_lines a,
    qp_pricing_attributes b,
    oe_order_lines_all c
    where a.list_line_id = b.list_line_id
    and a.list_line_type_code = 'PLL'
    and b.product_attribute_context = 'ITEM'
    and b.product_attribute = 'PRICING_ATTRIBUTE1'
    and c.inventory_item_id = b.product_attr_value
    and c.pricing_quantity_uom = b.product_uom_code
    and a.arithmetic_operator = 'UNIT_PRICE'
    and c.header_id = :header_id
    and c.price_list_id = a.list_header_id
    and c.pricing_date between nvl(a.start_date_active,c.pricing_date)
    and nvl(a.end_date_active,c.pricing_date)
    Hope it helps,
    Ketter Ohnes

  • Strange behaviour of JDBC query for CHAR column

    Hi,
    I have a simple table with char type and several records in the table.
    create table char_test(str char(50));
    insert into char_test values ('abc');
    insert into char_test values ('abc ');
    insert into char_test values ('abc ');
    In JDBC, if I have a query like
    PreparedStatement st = conn.prepareStatement("select str from char_test where str = 'abc'");
    ResultSet rs = st.executeQuery();
    All three rows will be returned.
    However, If I use parameter for the PreparedStatment, nothing will be returned if the value of the parameter is passed as "abc".
    PreparedStatement st = conn.prepareStatement("select str from char_test where str = ?");
    st.setString(1, "abc");
    ResultSet rs = st.executeQuery();
    Personally, I think this is a bug of Oracle JDBC driver. Could anybody please give me any explanation?
    Thanks,
    Bill
    PS. I'm using Oracle 10g Release 2 DB and ojdbc14.jar under jdk 1.5.

    Hello Bill,
    Have you solved your problem ?
    I have encountered a similar one and found a strange behavior of JDBC driver for PrepareStatement : in some cases, deep in JDBC driver, the parameter values could'nt be convert and are send as null values to the server.
    Here are partial driver logs, the first for a program which works fine and the second for one which turns on error.
    ============================
    <record>
    <date>2006-09-06T16:27:43</date>
    <millis>1157552863218</millis>
    <sequence>335</sequence>
    <logger>oracle.jdbc.conversion</logger>
    <level>FINE</level>
    <class>oracle.jdbc.driver.DBConversion</class>
    <method>javaCharsToCHARBytes</method>
    <thread>10</thread>
    <message>DBConversion.javaCharsToCHARBytes(chars[]= (26 bytes):
    00 0c 00 65 00 78 00 70 00 73 00 74 00 6f 00 0a 00 73 00 6c
    00 65 00 65 00 70 , charOffset=1, bytes[]= (7 bytes):
    00 00 00 00 00 00 00 , byteOffset=0, cs=178, nchars=6)</message>
    </record>
    <record>
    <date>2006-09-06T16:27:43</date>
    <millis>1157552863218</millis>
    <sequence>336</sequence>
    <logger>oracle.jdbc.conversion</logger>
    <level>FINE</level>
    <class>oracle.jdbc.driver.DBConversion</class>
    <method>javaCharsToCHARBytes</method>
    <thread>10</thread>
    <message>DBConversion.javaCharsToCHARBytes(chars, nchars, bytes[], cs): returned 6</message>
    </record>
    =============================
    javaCharsToCHARBytes gets 6 characters OK
    =============================
    <record>
    <date>2006-09-06T16:12:32</date>
    <millis>1157551952843</millis>
    <sequence>333</sequence>
    <logger>oracle.jdbc.conversion</logger>
    <level>FINE</level>
    <class>oracle.jdbc.driver.DBConversion</class>
    <method>javaCharsToCHARBytes</method>
    <thread>10</thread>
    <message>DBConversion.javaCharsToCHARBytes(chars[]= (40 bytes):
    00 26 00 73 00 74 00 6f 00 72 00 61 00 67 00 65 00 5f 00 53
    00 74 00 6f 00 72 00 65 00 2e 00 71 00 75 00 65 00 72 00 79 , charOffset=1, bytes[]= (20 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 , byteOffset=0, cs=178, nchars=19)</message>
    </record>
    <record>
    <date>2006-09-06T16:12:32</date>
    <millis>1157551952843</millis>
    <sequence>334</sequence>
    <logger>oracle.jdbc.conversion</logger>
    <level>FINE</level>
    <class>oracle.jdbc.driver.DBConversion</class>
    <method>javaCharsToCHARBytes</method>
    <thread>10</thread>
    <message>DBConversion.javaCharsToCHARBytes(chars, nchars, bytes[], cs): returned 0</message>
    </record>
    =============================
    javaCharsToCHARBytes gets 0 characters instead of 19
    But I am unable to discover the differences between the 2 programs in the JDBC driver usage.
    Does this sounds familiar to someone ?
    François

  • Need query for Item - Price Change History

    I need help finding information around Price Change History by Price List. 
    Information of interest is Date of Update and By Whom.    Also, if a Datasource is 'N-Unknown', what does this generally mean?
    select
    i.itemcode,
    i.itemname,
    iphist.price,
    pl.listname,
    pl.datasource as 'ChangeSource',
    '' as 'PriceChangeUpdateDate',
    '' as 'UpdateByUser'
    from  ait1 iphist, oitm i, opln pl
    where 1=1
    and iphist.pricelist = pl.listnum
    and i.itemcode = iphist.itemcode
    and iphist.itemcode in ('1234')
    and pl.listnum in (6)
    thanks in advance...

    thanks for the quick response and i would love to spend time perusing the forum for this question but i didn't have time today.  i'll do that now though.
    what i'm mostly interested in is a chronological view (lastUpdateDate) of the change to pricing for an item in the system.  there is a lot of activity in our system around price changes for promotions and i want to keep track of when it's changed in the source system and pair that with our other downstream systems.
    i'm assuming we can add this functionality through a udf some way or maybe sp_TransNotification proc?

  • Query for displaying columns in reverse order ?

    Hi All,
    I want to select/display all the columns of a table in reverse order. The no. of columns is arbitrary.
    Can anyone please help me on this.\
    Regards
    -AKJ

    apart from the physical data store implementation,
    are columns actually guaranteed ordering ? Guaranteed.... probably not, but they are in the data dictionary in the order in which they are created, so are known to be consistent in that respect.
    I don't think it's correct to refer to C(1)...C(n) ,
    they are just columns, there's no particular reason
    why one should come first or lastLikewise, I don't see the point in selecting columns out in a particular order unless you're trying to spool the output to a file.

  • Dynamic column change in Alv

    Hello friends,
                       Can any1 pls tell me if there is a function module available which can be used for dynamic column change in ALV.
                      Pls also elaborate how to use it.....

    While filling the field catalog you can specify witht IFcondition.
    Just see a example below...
    FORM field_fill USING pt_fieldcat TYPE slis_t_fieldcat_alv.
      DATA : ls_fieldcat TYPE slis_fieldcat_alv,
             pos TYPE i VALUE 1.
      ls_fieldcat-col_pos       = pos.
      ls_fieldcat-fieldname     = 'C_ICON'.
      ls_fieldcat-seltext_m     = 'Change Status'.
      ls_fieldcat-tabname       = 'IT_OUTPUT'.
      APPEND ls_fieldcat TO pt_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       = pos.
      ls_fieldcat-fieldname     = 'BUKRS'.
      ls_fieldcat-ref_fieldname = 'BUKRS'.
      ls_fieldcat-ref_tabname   = 'ANLA'.
      APPEND ls_fieldcat TO pt_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       = pos.
      ls_fieldcat-fieldname     = 'ANLN1'.
      ls_fieldcat-ref_fieldname = 'ANLN1'.
      ls_fieldcat-ref_tabname   = 'ANLA'.
      APPEND ls_fieldcat TO pt_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       = pos.
      ls_fieldcat-fieldname     = 'ANLN2'.
      ls_fieldcat-ref_fieldname = 'ANLN2'.
      ls_fieldcat-ref_tabname   = 'ANLA'.
      APPEND ls_fieldcat TO pt_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      IF p_farea = 'X'. " Conditional Based OUTPUT
        ls_fieldcat-col_pos       = pos.
        ls_fieldcat-fieldname     = 'GRUFL'.
        ls_fieldcat-ref_fieldname = 'GRUFL'.
        ls_fieldcat-ref_tabname   = 'ANLA'.
        APPEND ls_fieldcat TO pt_fieldcat.
        CLEAR ls_fieldcat.
        pos = pos + 1.
        ls_fieldcat-col_pos       = pos.
        ls_fieldcat-fieldname     = 'GRUFL_N'.
        ls_fieldcat-seltext_l     = 'New Floor Area'.
        ls_fieldcat-tabname       = 'IT_OUTPUT'.
        APPEND ls_fieldcat TO pt_fieldcat.
        CLEAR ls_fieldcat.
        pos = pos + 1.
      ENDIF.
      IF p_ldate = 'X'. " Conditional Based OUTPUT
        ls_fieldcat-col_pos       = pos.
        ls_fieldcat-fieldname     = 'LEABG'.
        ls_fieldcat-ref_fieldname = 'LEABG'.
        ls_fieldcat-ref_tabname   = 'ANLA'.
        APPEND ls_fieldcat TO pt_fieldcat.
        CLEAR ls_fieldcat.
        pos = pos + 1.
        ls_fieldcat-col_pos       = pos.
        ls_fieldcat-fieldname     = 'LEABG_N'.
        ls_fieldcat-seltext_l     = 'New Lease St.Date'.
        ls_fieldcat-tabname       = 'IT_OUTPUT'.
        APPEND ls_fieldcat TO pt_fieldcat.
        CLEAR ls_fieldcat.
        pos = pos + 1.
      ENDIF.
      ls_fieldcat-col_pos       = pos.
      ls_fieldcat-fieldname     = 'MESSAGE'.
      ls_fieldcat-seltext_l     = 'Status Message'.
      ls_fieldcat-tabname       = 'IT_OUTPUT'.
      APPEND ls_fieldcat TO pt_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
    ENDFORM.                    " field_fill
    Regards
    Gopi

  • Setting sql for a column

    Hi, is there a way to set sql query for a column?
    the query should take value from column in the table.
    in my case, it has come down for a need to have a nested select query inside my query:
    select app.application_id,
    (SELECT LISTAGG(typ.verification_name, ', ') WITHIN GROUP (ORDER BY typ.verification_id) FROM
    typ,chk where
    chk.application_id = app.application_id
    GROUP BY app.application_id ) AS verification_type,
    from tablea,tableb where....
    <note that application_id is coming from the bigger query , aka another column from another table.>
    i've tried
    CAST ( EVALUATE_AGGR('LISTAGG(%1,%2) WITHIN GROUP (ORDER BY %3 DESC)', "typ"."verification_name", ', ', "chk "."application_id ") AS CHARACTER ( 50 ))
    but my query need more than few EVALUATE_AGGR resulting in huge query in the log plus it's hard to put more details from other tables when you do this since everything buble down to the group by in the end of the query.
    pls help if there's something even close to this

    Hi jan ,
    thanx for your interest but let me clear with my requirement. What I want to do is that after executing the view query I want to navigate through records and sets some property or a group of property ( think it as a java object which holds properties ) for that cell and after that when I Navigate through record I don't want to run my logic for calculating properties again and I should be able to get those properties which I set earlier. There can be any number of records and most of time value will remain same then why should I calculate properties every time I navigate.
    Currently I am storing these values in a separate class (with row and column no.)but now I am searching some way so that I can store those values in my view only.
    Is it possible in BC4J view ? I heard that something like this is provided in BC4J view but not able to find out..
    thanx once again
    I welcome some other suggestions on it..

  • Changing font color in a report using SQL query for APEX 5.0

    Hello,
    I am testing APEX 5.0 in my testing environment to see if I can migrate my internal apps from 4.2 to 5.0.
    How can I change the font color in a field based in the SQL query? I know how to do it in 4.2 but I can't find the same in 5.0.
    Thanks,

    Well, I used to put the html tags in the select as text getting the color value depending a CASE , then I had to change the Display attribute for the column in the report as "Display as text (espace special characters...)".
    I found an old post here: https://tylermuth.wordpress.com/2007/12/01/conditional-column-formatting-in-apex/ and  this method still worked for me in APEX 5.0
    Thanks anyways

  • Average Calculation for the Dynamically Changing Columns

    Hello Experts,
    We have to design the following scenario in a query in the query designer.
    Variable Selection = 0CALMONTH Range Value
    The Report Data should be as below
    For Example: 0CALMONTH = MONTH1 to MONTH3
    MONTH1--MONTH2--
    MONTH3
    Statistical Forecast %-- A%B%--
    C%
    MAPE--(A%B%C%)/3(A%B%C%)/3--
    (A%B%C%)/3
    For Example: 0CALMONTH = MONTH1 to MONTH5
    MONTH1--MONTH2MONTH3MONTH4--
    MONTH5
    Statistical Forecast %--A%B%C%D%--
    E%
    MAPE--(A%B%C%D%E%)/5(A%B%C%D%E%)/5----(A%B%C%D%E%)/5   .............
    In this report the number of columns will be dynamically changing depending on the 0CALMONTH range value and we need to calculate the MAPE value which is equal to the average value of Statistical Forecast %.
    Can someone please provide me the inputs on how to calculate the MAPE value for the dynamically changing columns.
    Regards,
    AVS Reddy

    Victor,
    I have this code here
    AVG(DESCENDANTS(COSTCENTER.H1.Currentmember,1))
    Working for me right now, without using the second parameter on the AVG function, and 1 for te descendants, and the first decendants of the current acount are not the base level of the hierarchy.
    And if you need to specify the lowest leves to get it to work something is wrong.
    Use the formula above and try optimizing you application.
    Best
    Leandro

  • Report or Query for analysing Changes made in a Purchase Order

    Hi All,
    Item changes to a PO can be seen easily by using Environment-->Item Changes.
    Is there a way to use this as a query or report so it is possible to search many PO's at the same time to find the date of a specific change. For example, delivery date completed flag set to complete, see the date this was made.
    Thanks.

    Hi,
    SAP has provided two reports that you can use for capturing all changes you have made to your POs -
    1)   RSSCD100; and
    2)   CHANGEDOCU_READ
    Both reports shall be run with Object Class EINKBELEG.
    Cheers,
    HT

  • [Oracle 8i] Query for N rows by column value?

    I was just wondering if what I want to do is possible within my query (rather than programmatically)...
    I want to return the N most recent records for each unique value in a particular column.
    Here's a sample table:
    CREATE TABLE     orders
    (     order_no     numeric(10)
         part_no          varchar(5)
         close_date     date
         order_qty     numeric(10)
         scrap_qty     numeric(10)
         CONSTRAINT order_pk PRIMARY KEY (order_no)
    );And some sample data....
    INSERT INTO     orders     VALUES
    (0000012345,'ABC-1',TO_DATE('01-01-2010','mm-dd-yyyy'),10,1);
    INSERT INTO     orders     VALUES
    (0000013498,'ABC-1',TO_DATE('01-05-2010','mm-dd-yyyy'),12,2);
    INSERT INTO     orders     VALUES
    (0000033452,'ABC-1',TO_DATE('01-10-2010','mm-dd-yyyy'),5,0);
    INSERT INTO     orders     VALUES
    (0000001468,'ABC-1',TO_DATE('01-15-2010','mm-dd-yyyy'),15,1);
    INSERT INTO     orders     VALUES
    (0000022349,'BR723',TO_DATE('01-03-2010','mm-dd-yyyy'),8,1);
    INSERT INTO     orders     VALUES
    (0000069581,'BR723',TO_DATE('01-05-2010','mm-dd-yyyy'),5,0);
    INSERT INTO     orders     VALUES
    (0000436721,'BR723',TO_DATE('01-10-2010','mm-dd-yyyy'),14,1);
    INSERT INTO     orders     VALUES
    (0000213446,'A5001',TO_DATE('01-06-2010','mm-dd-yyyy'),5,1);
    INSERT INTO     orders     VALUES
    (0000327987,'A5001',TO_DATE('01-08-2010','mm-dd-yyyy'),5,0);
    INSERT INTO     orders     VALUES
    (0000041353,'A5001',TO_DATE('01-14-2010','mm-dd-yyyy'),12,1);
    INSERT INTO     orders     VALUES
    (0000011241,'A5001',TO_DATE('01-15-2010','mm-dd-yyyy'),5,1);In this example, what I want to return are the 2 most recent orders (by close_date) for each part number.
    Here is a table with the results I want to get, based on the scenario above:
    order_no     part_no          close_date     order_qty     scrap_qty
    0000001468     'ABC-1'          '01-15-2010'     15          1
    0000033452     'ABC-1'          '01-10-2010'     5          0
    0000436721     'BR723'          '01-10-2010'     14          1
    0000069581     'BR723'          '01-05-2010'     5          0
    0000011241     'A5001'          '01-15-2010'     5          1
    0000041353     'A5001'          '01-14-2010'     12          1Is it possible to write a query to get these results, or am I going to have to query for all available data, and find the 2 most recent rows programmatically?
    Thanks in advance!

    Hi,
    user11033437 wrote:
    I'm going to test that out right now. I think if it works, I may need to use dense_rank() rather than rank(), because it is possible that two orders for the same part number could have the same close date, and according to what I've looked up on the rank() and dense_rank() functions, rank() can give non-consecutive results if the values are the same.What's wrong with non-consecutive values?
    Use RANK, DENSE_RANK or ROW_NUMBER depending on what you want.
    For example; say a certain part has been ordered 8 times:
    3 times with close_date January 29, 2010 (all at exactly the same time),
    4 times with close_date January 28, 2010 (all at exactly the same time), and
    1 time with close_date January 27, 2010.
    If you ask for the last 2 rows:
    RANK will give you the 3 rows from January 29. (All 3 have an equal claim to being in the top 2.)
    DENSE_RANK will give you the 7 rows from January 28-29 (the last two values , regardless of how many rows have them).
    ROW_NUMBER will give you 2 rows from January 29. (Which 2? It's arbitrary unless you add a tie-breaker to the ORDER BY clause.)
    All these functions are available in Oracle 8.1.

Maybe you are looking for

  • The Folder "iTunes" cannot be found or created - ERROR!

    I have been using iTunes for about five months and have loaded about 5500 songs onto it from my CDs. I've been on it A LOT! All of a sudden, it won't open and gives me this message: The Folder "iTunes" cannot be found or created, and is required. The

  • Need Help in reading data from URLConnection in servlets

    hi i created GUI which sends d username n password to the servlets via URLConnection.n am sending the same to Server program via sockets.but when i read d data in the servlet am getting only null value...need help here.... This is my button's ActionP

  • Any idea how to use AUTHORITY_CHECK_DATASET

    Hello Friends,    anybody knows how to use these FM 'AUTHORITY_CHECK_DATASET' and FILE_GET_NAME_USING_PATH.    i know the logical path has been created in my system as 'zzzzz' but i don't how to use that. thanks, john.

  • Error when launching Workflow Editor

    Hi gurus, I am expriencing an error when i try to launch the Workflow editor from the Workflow definition page (Actions -> Launch Workflow editor). The error is: Unable to load resource: http://jawe.enhydra.org/twe.jnlp I have the latest JRE installe

  • Taking more time while generating webhelp.

    I am updating the MBDB manual using RoboHelp.  This manual consists of 9 projects that are merged into 1 (or over 16,000 documents total).  For each project I open it, add new or make revisions to the documents within and generate the document.  It i