473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

can this be done with one query?

I have 3 fields
id result date
1 1 11/11/02
1 2.3 12/12/03
1
1 4.6 06/04/04

can one query give me all these things?
the min result record 1 1 11/11/02
the first result based on date 1 1 11/11/02
the maximum result info. 1 4.6 06/04/04
thanks for the info

jerry

Nov 13 '05 #1
1 1023
"sparks" <sp****@here.com> wrote in message
news:iq********************************@4ax.com...
I have 3 fields
id result date
1 1 11/11/02
1 2.3 12/12/03
1
1 4.6 06/04/04

can one query give me all these things?
the min result record 1 1 11/11/02
the first result based on date 1 1 11/11/02
the maximum result info. 1 4.6 06/04/04


This could be slow on large tables. A better way might be to turn the
aggregated list into a derived table and join it back to the original table
to get the related record info - post back if you need that one instead.
Otherwise this should work:
select r.id, min(r.result) as minResult,
(
select r2.[date]
from results r2
where r2.id = r.id
and r2.result =
(
select min(r3.result)
from results r3
where r3.id = r.id
)
) as minResultDate,
(
select r2.result
from results r2
where r2.id = r.id
and r2.[date] =
(
select min(r3.[date])
from results r3
where r3.id = r.id
)
) as firstResult,
max(r.result) as maxResult,
(
select r2.[date]
from results r2
where r2.id = r.id
and r2.result =
(
select max(r3.result)
from results r3
where r3.id = r.id
)
) as maxResultDate
from results as r
group by r.id
order by r.id
Nov 13 '05 #2

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

Similar topics

1
by: YoBro | last post by:
Lets say I wanted to select all employees and list their occupations. I have this query: SELECT * FROM employees, job WHERE employees.id=job.id Now some employees might have more than one job. I...
3
by: David Mills | last post by:
Hello, looking for some input on how to do this query. (I'm using Access) John Doe 123 Main St Chicago 123 John Doe 123 Main St Chicago 456 John Doe 123 Main St Chicago 789 Given the...
3
by: Matthew Kramer | last post by:
How would be the best way to do this in Access? I have two tables. The first table has all the rows of data. The first column of this table has a country name, the second has a year and the...
4
by: sparks | last post by:
We have a database that reads in and formats raw data. We were using queries to format the data per person and outputing reports. The other database has the persons personal information. I changed...
6
by: Mike | last post by:
I'm creating a dataset and get my data from the db table such as PA, PA, WA, WA CA, DE, DE, DE, FL, WI. is there a way to do a select on that dataset and populate a drop down box such as CT, DE,...
3
by: Miguel Dias Moura | last post by:
Hi, When I subscribe a web site I usually receive an email to confirm my subscription. Only after I follow the link in the email my account gets activated. In general, how is this done? Can...
3
by: Danny Nielsen | last post by:
Hi I am having trouble figuring out how to use combobox in a datagridview. What seemed to be a simple task turned out not to arrghh. I have a dataGridView with 4 columns, one of them is column...
5
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the...
7
by: isdeveloper | last post by:
Hi All, I have a problem with a table that I want to get nice data out of in a single query. The guys here reckon it can't be done in a single query but I wanted to prove them wrong !!...
5
by: dee | last post by:
I would like to update one specific table field in each of 8 records, using different data for each. Is it possible to update one field in 8 different records in one query?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.