Welcome to SPN

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

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

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
    Anyone Have Any Unanswered Questions On Sikhi Or God? Sikh Sikhi Sikhism Jan 7, 2017
    Question About Translations Questions and Answers Dec 20, 2016
    Question About GGS Questions and Answers Aug 28, 2016
    Marriage And Discrimination Related Questions Blogs Mar 21, 2016

  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
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page