Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

SQL question

Discussion in 'Information Technology' started by DBARNETT@CCC.HSHS.ORG, Jul 28, 2006.

Tags:
  1. DBARNETT@CCC.HSHS.ORG

    DBARNETT@CCC.HSHS.ORG
    Expand Collapse
    Guest

    Hi

    I have a table with an ITM_NO and a PO_Date and a few other fields.
    There are duplicate Table entries with the same ITM_NO and different
    PO_Dates.

    What I need to do is get 1 table entry for each Unique ITM_NO but the
    entry that has the most recent PO_Date.

    ITM_NO PO_DATE OTHER
    123 1/27/2006 a
    123 6/20/2006 b
    123 5/14/2005 c

    456 3/15/2007 d
    456 4/15/2007 e
    456 5/15/2007 f

    Should yield:
    123 6/20/2006 b
    456 5/15/2007 f

    Thanks for your help
    Dennis
     
  2. Loading...

    Similar Threads Forum Date
    Microsoft Brings 64-Bit Perks in SQL Server 2000 Service Pack (Ziff Davis) Interfaith Dialogues May 7, 2005
    Question About GGS Questions and Answers Aug 28, 2016
    Marriage And Discrimination Related Questions Blogs Mar 21, 2016
    Sikhi Questioning Faith Sikh Sikhi Sikhism Mar 3, 2016
    Entering into Sikhism: Questions on Reht Maryada. Blogs Oct 22, 2015

  3. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On 20 Jul 2006 14:14:17 -0700, DBARNETT@CCC.HSHS.ORG wrote:

    >What I need to do is get 1 table entry for each Unique ITM_NO but the
    >entry that has the most recent PO_Date.
    >
    >ITM_NO PO_DATE OTHER


    A Subquery will do this:

    SELECT ITM_NO, PO_DATE, OTHER
    FROM mytable
    WHERE PO_DATE = (SELECT Min(PO_DATE FROM mytable AS A
    WHERE A.ITM_NO = mytable.ITM_NO);


    John W. Vinson[MVP]
     
  4. Joan Wild

    Joan Wild
    Expand Collapse
    Guest

    SELECT ITM_NO, Max(PO_DATE) AS MaxOfPO_DATE
    FROM SomeTable
    GROUP BY ITM_NO;

    However since you also want to get a related piece of information i.e.
    other, you'll need to use one of the methods outlined at
    http://www.mvps.org/access/queries/qry0020.htm

    --
    Joan Wild
    Microsoft Access MVP

    DBARNETT@CCC.HSHS.ORG wrote:
    > Hi
    >
    > I have a table with an ITM_NO and a PO_Date and a few other fields.
    > There are duplicate Table entries with the same ITM_NO and different
    > PO_Dates.
    >
    > What I need to do is get 1 table entry for each Unique ITM_NO but the
    > entry that has the most recent PO_Date.
    >
    > ITM_NO PO_DATE OTHER
    > 123 1/27/2006 a
    > 123 6/20/2006 b
    > 123 5/14/2005 c
    >
    > 456 3/15/2007 d
    > 456 4/15/2007 e
    > 456 5/15/2007 f
    >
    > Should yield:
    > 123 6/20/2006 b
    > 456 5/15/2007 f
    >
    > Thanks for your help
    > Dennis
     

Share This Page