Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    7

    Unanswered: SQL to retrieve the latest record

    I'm trying to write a query to achieve the following result for the sample data below. Any help is much appreciated.Please ignore all the ** with the data, i was just trying to align the data below the column name.

    Table-A

    ID-column1*** FK-column2** Date-column3
    DD1000000*** D4Q0000**** null

    Table-B

    Id-column1** Num-column2**** Cd-Column3
    D4Q00000*** 0000********** AA1
    D4Q11111*** 1111********** AA2
    D4Q22222*** 2222********** AA3

    Expected Result Set /* Record with Max value in Num need to be retrieved.

    ID-column1* Fk-column2** Num-Column3*** Cd-column4
    DD1000000* D4Q22222****** 2222******** AA3
    Last edited by DB2begin; 05-14-15 at 00:40.

  2. #2
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    You have to use a sub-query. Show us what you have now and we can guide you.
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    how do you 'know' what is the latest record?
    how do you associate table a to table b
    I can understand why you might want to mask/hide your table and column names but it doesn't help when asking for help if you have a column of the same name in two tables, yet the relations hip betweent he two tables is, seemingly, on another column in table a
    I'd rather be riding on the Tiger 800 or the Norton

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •