Article View: bit.databases.mssql-l
Article #204Subject: SQL Query - MAX, Grouping and Sub query
From: Phil
Date: Tue, 24 Sep 2002 10:06
Date: Tue, 24 Sep 2002 10:06
38 lines
2113 bytes
2113 bytes
Hi I am tryring to extract the most recent record from a table for a given ID number. i.e. mainID subID Date_updated Details...... 20 101 10/02/2002 ........... 20 101 14/04/2002 ........... 20 102 15/03/2002 ............ 20 102 15/06/2002 ................ I thought I could use grouping and MAX function i.e. SELECT max(date_updated) as MaxDate, subID, policyID WHERE mainID = 20 GROUP BY subID this returns ID subID Date_created 20 101 14/04/2002 20 102 15/06/2002 this is good, however I need to return the other details in the table. By selecting more fields to display it does not work as it wants to group them. By putting this query into a sub query you are unable to do so as it returns 2 fields Date_created (for the max date thing) and Benefit ID which is what i want to display the record by. Any ideas anyone? TIA Phil
Technical Details
Message-ID:
<3d9039e3$0$25044$afc38c87@news.easynet.co.uk>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!easynet-quince!mango.news.easynet.net!easynet.net!easynet-post1!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f6611,8c478b0c44e242bf,start X-Google-Attributes: gidf6611,public X-Google-ArrivalTime: 2002-09-24 03:14:01 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!easynet-quince!mango.news.easynet.net!easynet.net!easynet-post1!not-for-mail From: "Phil" <phil@phish.fslife.co.uk> Newsgroups: bit.databases.mssql-l Subject: Subject: SQL Query - MAX, Grouping and Sub query Date: Tue, 24 Sep 2002 11:06:47 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Lines: 42 Message-ID: <3d9039e3$0$25044$afc38c87@news.easynet.co.uk> Organization: [posted via Easynet UK] NNTP-Posting-Host: 217.204..news.easynet.co.uk X-Trace: DXC=TVNQ75Z99L<UQ\99HOh=4>mTHc[HV;eV55BX@\nIAQ\6aWei;0FT]h>