t-sql joins help

  • I have Material table

    MfgDate Id Name

    2009-04-16 1 Capacitor

    2009-04-12 2 PCB

    2009-04-16 3 Diode

    I have a store table

    StoredDate Id Name

    2009-04-16 1 Capacitor

    2009-04-12 2 PCB

    2009-04-15 3 Diode

    2009-04-15 1 Capacitor

    2009-04-11 2 PCB

    2009-04-11 3 Diode

    2009-04-10 1 Capacitor

    2009-04-10 2 PCB

    2009-04-10 3 Diode

    I want ouput like where Storeddate is max date but not equal to MfgDate

    Id Name MfgDate StoredDate

    1 Capacitor 2009-04-16 2009-04-15

    2 PCB 2009-04-12 2009-04-11

    3 Diode 2009-04-16 2009-04-13

  • Will something like this do what you need?

    SELECT

    Material.Name,

    MfgDate,

    MAX(StoredDate) AS StoredDate

    FROM

    Material

    LEFT OUTER JOIN Store

    ON Material.ID = Store.ID

    AND StoredDate > MgfDate

    GROUP BY

    Material.Name,

    MfgDate ;

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply