|
SELECT A.A8FYCD, A.A8HFCD, A.A8E6TX, max(A.A8IONB)max_edition_date, B.MAXSYMBOL FROM Library.File AS A INNER JOIN (SELECT A8FYCD, A8HFCD, A8E6TX, MAX(A8ALIFTE) AS MAXSYMBOL, A8IONB FROM Library.file GROUP BY A8FYCD, A8HFCD,A8E6TX,A8IONB) AS B ON A.A8FYCD = B.A8FYCD AND A.A8HFCD = B.A8HFCD AND A.A8E6TX = B.A8E6TX AND A.A8IONB = B.A8IONB GROUP BY A.A8FYCD, A.A8HFCD,A.A8E6TX,A.A8IONB,B.MAXSYMBOL ORDER BY A.A8FYCD asc, A.A8HFCD,A.A8E6TX,A.A8IONB,B.MAXSYMBOL Returns from the table Name Year make Date Sym Acur 00 3.2TL blank 18 Acur 00 3.2TL 1000 15 The above gets me 2 lines like the sample output above. I just want to return that 2nd line from above which is the highest date (1000) and the highest symbol associated with that date. Below is sample of the db Name Year make Date Sym Acur 00 3.2TL blank 18 Acur 00 3.2TL blank 17 Acur 00 3.2TL 1000 15 Acur 00 3.2Tl blank 14 -----Original Message----- From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Mark Adkins Sent: Friday, December 08, 2006 11:13 AM To: midrange-l@xxxxxxxxxxxx Subject: RE: Need help with SQL query Here is another solution. It is pretty elegant IMO: SELECT A.FNAME, A.LNAME, MAX(A.AGE), B.MAXSALARY FROM TABLE AS A INNER JOIN (SELECT FNAME, LNAME, MAX(SALARY) AS MAXSALARY FROM TABLE GROUP BY FNAME, LNAME) AS B ON A.FNAME = A.FNAME AND A.LNAME = B.LNAME AND A.SALARY = B.MAXSALRY GROUP BY A.FNAME, A.LNAME Mark
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.