Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I love the structure of the site. You start at the top, and drill down to what you want. Maybe I've been using Unix too long... :-) "

Geography

Where in the world do Tek-Tips members come from?
dheim70 (Programmer)
13 Apr 12 11:05
Hi, I am a Total SQL novice, but need to do this. I have a table as follows:

Contract_No   ProgressID  ReportingPeriod  ReportingYear FinalFlag
2185              721         Jan-Dec            2010            Y
2185              831         Jun-Aug            2011            N
2190              895         jun-Sep            2011            Y
2190              840         Jun-Sep            2009            N

The rows I need to pull are the Max of progressID by Contract_No but full row. ie in the example above the query would pull rows 2 and 3 (All 5 fields). Any time I attempt any of this I get various error messages that all fields have to be done as aggregates and can't do grouping if fields are not all aggregates.I'm desparate and any help would be greatly appreciated! Thanks! D  
Helpful Member!  SQLScholar (Programmer)
13 Apr 12 11:36
something like this

SELECT *
from
DataTable
INNER JOIN (

select contract_no, max(progressID) as maxProgID From DataTable) MaxList
on maxlist.contract_no = DataTable.contract_no and maxlist.maxProgID =DataTable.progressID

so its a self referencing query.  So the Inner join queries the table to find the max for each entry.  Then joins back to the main table to pull all of the data for that row.

Hope this helps

Dan

----------------------------------------
www.fountain.me.uk

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close