home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / database / 9430 < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.4 KB  |  49 lines

  1. Newsgroups: comp.databases
  2. Path: sparky!uunet!ukma!darwin.sura.net!sgiblab!munnari.oz.au!metro!usage!s9100786
  3. From: s9100786@cumulus.csd.unsw.oz.au (Matthew Jackson)
  4. Subject: SQL Question
  5. Message-ID: <1993Jan27.214645.12939@usage.csd.unsw.OZ.AU>
  6. Sender: news@usage.csd.unsw.OZ.AU
  7. Nntp-Posting-Host: aix00.csd.unsw.oz.au
  8. Reply-To: M.Jackson@unsw.edu.au
  9. Organization: School of Banking and Finance, University of New South Wales
  10. X-Newsreader: TIN [version 1.1 PL8]
  11. Date: Wed, 27 Jan 1993 21:46:45 GMT
  12. Lines: 35
  13.  
  14. Is it possible to do the following in SQL ? I can't seem to get the
  15. correct code.
  16.  
  17. I have a table which contains some data which looks like this
  18.     identifier year code value
  19.  
  20. I want to pick out the row with the latest year for each identifier for
  21. a given code
  22.  
  23. ie say I am looking for a code of "xyz", I want to see all those
  24. identifiers which have that code but only the greatest year. 
  25.  
  26. The problem is that each identifier may end at a different year
  27.  
  28. I tried 
  29.  
  30. select identifier, max(year), code, value
  31. from tablename
  32. where code = "xyz"
  33. group by identifier;
  34.  
  35. but this gives the maximum year of all identifiers not the individual
  36. maxima.
  37.  
  38. Any advice would be appreciated.
  39.  
  40. Thanks,
  41.  
  42. --
  43. Matthew Jackson                       | Computing Officer
  44. M.Jackson@unsw.edu.au                 | School of Banking and Finance
  45. 61-2-697-3553                         | University of New South Wales
  46.                                       | Sydney, Australia
  47.  
  48.             Olympics for Sydney in 2000
  49.