473,661 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find maximum value in one field per each group

I need a stored procedure or other method to find the maximum value
for each set of records. I would want to eliminate all of the non-
maximum records. An example of the data is below. For the example
below, I would want to return record 2,6,7, and 10. To pick between 7
and 8, I would want to pick the one with the minimum ID. Can anyone
supply some sample code? Note that some people may have only one
record.
ID Person Salary
1 44 20000
2 44 22000
3 44 21000
4 45 50000
5 45 51000
6 45 53000
7 46 45000
8 46 45000
9 46 40000
10 47 10000

Aug 4 '07 #1
1 3958
http://www.mvps.org/access/queries/qry0020.htm

ar****@yahoo.co m wrote:
I need a stored procedure or other method to find the maximum value
for each set of records. I would want to eliminate all of the non-
maximum records. An example of the data is below. For the example
below, I would want to return record 2,6,7, and 10. To pick between 7
and 8, I would want to pick the one with the minimum ID. Can anyone
supply some sample code? Note that some people may have only one
record.
ID Person Salary
1 44 20000
2 44 22000
3 44 21000
4 45 50000
5 45 51000
6 45 53000
7 46 45000
8 46 45000
9 46 40000
10 47 10000
Aug 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2960
by: Siemel Naran | last post by:
Hi. I have a table of products and versions, and these 2 columns are the unique key. My challenge is to write a SQL statement to find the latest version of each product. My solutions below seem correct, yet MySql complains that the syntax is incorrect. How to fix? And which solutions are MySql specific, and which are ANSISql (for
0
5277
by: Matt | last post by:
I am running CR 8.5 from a (large) SQL Server db. My aim is to use crystal enterprise so end users in our sales team can access reports on demand for a given date range and client so I am trying to keep contact with the database to a minimum. IE currently processign a report takes about 10 minutes and involves manually running stored procs in sql server to produce smaller, client specific temporary tables that CR can easily cope with. ...
1
1920
by: K. Davis | last post by:
I need to increment the maximum value of a field of a table by 1 when a form opens a blank record. (e.g. =max(!![trip_number}) so the logic and references are working at the form level. I've tried a number of variants tied to the before update event, but always get the message "The field 'tripmain.trip_number' can't contain a Null value because the Required property for this field is set to True. Enter a value in this field."
0
1812
by: JR | last post by:
Hi, i found a user control on the net see code below it is part of VSEssential but I like the coolProgressBar. Zo I want to use it into my program and I always get the error that it can't find the control or the control isn't into the toolbar Who has an idee Jan
1
2268
by: VG | last post by:
Hi folks, I have procedure that I am using to assign ID number vs Autonumber. It is working fine but something going wrong with my form that I have to replace the form with old version to make it working again. It has happened about 10 times for the last 6 month. The error message is "MS Access can't find the field 'I' referred to in your expression. Please advise what is going wrong. The procedure is as follows: Private Sub...
3
10901
by: jshunter | last post by:
Does anyone know of a built-in function to return the maximum possible value of a given datatype? I have to return the biggest value for a smalldatetime or datetime in a view if the field is null, but can't find such a function. The closest I've come is: select datalength(cast(getdate() as smalldatetime)) ....but that only return the number of bytes, not the value itself, which is '6-6-2079 11:59'
2
2693
by: MyGreatProgramme | last post by:
I want to make a delete query that deletes all the items that are in the minorty. For example, in the field " Houses " there are 10 rows with value 1 , 3 rows with value 3 and 4 rows with value 6. In this case I must delete all values except the value 1 I suppose the code should use Dcount, Max or something like that but I cannot do it. Any help ?"
2
6650
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI
4
3951
by: SjaakBanaan | last post by:
Hey all, I have a question that ought to be simple but has given me headaches for a while. I have a table with contact email addresses, say. T ID ContID Priority Emailaddress ----------------------------------------------
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8758
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.