View Single Post
  #2 (permalink)  
Old 02-02-10, 13:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
SELECT Table1.*
     , Table2.some_other_colulmn
  FROM Table1
INNER
  JOIN ( SELECT linkfield
              , MIN(datefield) AS min_date
           FROM Table2
         GROUP
             BY linkfield ) AS m
    ON m.linkfield = Table1.linkfield
INNER
  JOIN Table2
    ON Table2.linkfield = m.linkfield 
   AND Table2.datefield = m.min_date
notice that the SELECT clause contains "some other field" from Table2

if it was really the lowest datefield that you wanted, the query would be a lot simpler

usually, this type of situation wants to have some other column value on the row that has the lowest datefield for each group
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote