Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max() ? 1

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
BE
To simplify the question.

Code:
2009-01-01 | JEF | 1
2005-01-01 | ANN | 1
2001-01-01 | PET | 2

What I need, try to do is a query result where he group the number and take the highest date of each number.

The result I wish :

Code:
2009-01-01 | JEF | 1
2001-01-01 | PET | 2

But I got :
Code:
2009-01-01 | ANN | 1
2001-01-01 | PET | 2

ANN is not corresponding with the date, 2009-01-01, it should be JEF
I use the Max() function on date
 
Could you enlighten us with the query and a table defintion ?
 
Code:
$sql = "SELECT Max(tvme02_eig.EAkte) AS EEAkte, tvme02_eig.EEig, tvme01_app.App  FROM tvme02_eig INNER JOIN tvme01_app ON tvme02_eig.ErefApp = tvme01_app.ID_APP GROUP BY tvme02_eig.ErefApp";

EAkte : is a date
 
Code:
SELECT tvme02_eig.EAkte
     , tvme02_eig.EEig
     , tvme01_app.App  
  FROM tvme02_eig 
INNER 
  JOIN ( SELECT MAX(EAkte) AS EEAkte
              , ErefApp
           FROM tvme02_eig
         GROUP
             BY ErefApp ) AS m
    ON m.ErefApp = tvme02_eig.ErefApp
   AND m.EEAkte = tvme02_eig.EAkte
INNER
  JOIN tvme01_app 
    ON tvme01_app.ID_APP = tvme02_eig.ErefApp

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
My idea said it has something to do with a sub-query. I did a first test and now it seem to work correctly txs !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top