ProjectID with earliest WarrantyStart and the latest WarrantyEnd

D

deb

I have a query that has the field ProjectID, ProjectName, WarrantyStart and
WarrantyEnd. Data looks like this...

ProjectID ProjectName WarrantyStart WarrantyEnd
1 Alma 11-Mar-2008 13-Mar-2008
1 Alma 25-Mar-2008 25-Mar-2008
2 Bai 01-Jan-2008 01-Jan-2008
2 Bai 12-Jul-2006 23-Dec-2006
2 Bai 18-Jul-2006 18-Aug-2006
3 Athens 19-Mar-2008 25-Mar-2008
4 ABC 01-Apr-2009 17-Jun-2009

SQL looks like this...

SELECT t040Project.ProjectID, t040Project.ProjectName,
t72WarrantyDetails.WarrantyStart, t72WarrantyDetails.WarrantyEnd
FROM (t040Project INNER JOIN t71Warranty ON t040Project.ProjectID =
t71Warranty.ProjectID) INNER JOIN t72WarrantyDetails ON
t71Warranty.WarrantyID = t72WarrantyDetails.WarrantyID;

How can I have one record per ProjectID that has the earliest WarrantyStart
and the latest WarrantyEnd?
Data should look like this...

1 Alma 11-Mar-2008 25-Mar-2008
2 Bai 12-Jul-2006 01-Jan-2008
3 Athens 19-Mar-2008 25-Mar-2008
4 ABC 01-Apr-2009 17-Jun-2009

I am trying to get the span of time of all warranties for each project.
 
K

KARL DEWEY

Try this substituting your table name for Debbie --
SELECT Debbie.ProjectID, Debbie.ProjectName, Min(Debbie.WarrantyStart) AS
MinOfWarrantyStart, Max(Debbie_1.WarrantyEnd) AS MaxOfWarrantyEnd
FROM Debbie INNER JOIN Debbie AS Debbie_1 ON (Debbie.ProjectName =
Debbie_1.ProjectName) AND (Debbie.ProjectID = Debbie_1.ProjectID)
GROUP BY Debbie.ProjectID, Debbie.ProjectName;
 
A

akphidelt

Create a query... go to Totals

Group by ID
Group By Name
Min By WarrantyStart
Max Byx WarrantyEnd

This should do the trick in a query.
 
D

deb

Got a syntax error.

I tried the below suggestion from akphidelt and it worked

Thank you for your quick response
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top