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

  1. Newsgroups: comp.databases
  2. Path: sparky!uunet!sangam!cmie!rs
  3. From: rs@cmie.cmie.ernet.in (Rajappa Iyer)
  4. Subject: Re: SQL Question
  5. In-Reply-To: s9100786@cumulus.csd.unsw.oz.au's message of Wed, 27 Jan 1993 21:46:45 GMT
  6. Message-ID: <RS.93Jan28135822@cmie.cmie.ernet.in>
  7. Sender: rs@cmie.ernet.in (Rajappa Iyer)
  8. Organization: Centre for Monitoring Indian Economy
  9. References: <1993Jan27.214645.12939@usage.csd.unsw.OZ.AU>
  10. Date: Thu, 28 Jan 1993 08:58:22 GMT
  11. Lines: 22
  12.  
  13. In article <1993Jan27.214645.12939@usage.csd.unsw.OZ.AU> s9100786@cumulus.csd.unsw.oz.au (Matthew Jackson) writes:
  14.  
  15. >   I have a table which contains some data which looks like this
  16. >       identifier year code value
  17. >
  18. >   I want to pick out the row with the latest year for each identifier for
  19. >   a given code
  20.  
  21. I will use "identifier" as the key. If this is incorrect you will have
  22. to change the condition in the nested query.
  23.  
  24. SELECT identifier, year, code, value
  25.     FROM tablename t1
  26.     WHERE t1.code = "xyz" AND t1.year =
  27.     (SELECT max(year) FROM tablename t2 WHERE t1.identifier = t2.identifier)
  28.  
  29. --
  30. Rajappa Iyer            rs@cmie.ernet.in (Preferred)
  31.                 riyer@shakti.ncst.ernet.in
  32. -- 
  33. Rajappa Iyer            rs@cmie.ernet.in (Preferred)
  34.                 riyer@shakti.ncst.ernet.in
  35.