By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,549 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,549 IT Pros & Developers. It's quick & easy.

Query for Last Date in a table

oszapped
P: 1
I am new to creating SQL queries and need some help.

I am trying to query from three tables.
1 - A table with a list of Drawings (DRAWINGS)
2 - A table with the Revision history of the Drawings (REVISIONS)
3 - A table with the list of Projects (WRI_SITE_PRJS)

The result I am looking for:
Name of Drawing (I want to return the drawings that don't have a revision as well)
Last Drawing Revision
Date of Revision
Project that the drawing belongs on

The below query I created in access and the result was exactly what I was expecting.

SELECT DRAWINGLIST.NAME, DRAWINGLIST.WRI_DESCRIPTION AS [Drawing Title], LastRev.LastOfREVISIONNAME AS Rev, LastDate.LastOfREVISIONDATE AS [Rev Date], WRI_SITE_PRJS.TITLE AS Project
FROM LastRev RIGHT JOIN (LastDate RIGHT JOIN (DRAWINGLIST INNER JOIN WRI_SITE_PRJS ON DRAWINGLIST.WPRJID = WRI_SITE_PRJS.WPRJID) ON LastDate.NAME = DRAWINGLIST.NAME) ON LastRev.NAME = DRAWINGLIST.NAME
ORDER BY DRAWINGLIST.NAME;

I tried getting the same result in SQL and find that I can't GROUP BY the LAST date in a table. The result I'm getting is all the revisions for the drawing.

My question is: How do I query for the LAST date or revision in a table.

I'm using Microsoft SQL Server 2003

Some help is greatly appreciated.
OS
Jul 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: 93
I am new to creating SQL queries and need some help.

I am trying to query from three tables.
1 - A table with a list of Drawings (DRAWINGS)
2 - A table with the Revision history of the Drawings (REVISIONS)
3 - A table with the list of Projects (WRI_SITE_PRJS)

The result I am looking for:
Name of Drawing (I want to return the drawings that don't have a revision as well)
Last Drawing Revision
Date of Revision
Project that the drawing belongs on

The below query I created in access and the result was exactly what I was expecting.

SELECT DRAWINGLIST.NAME, DRAWINGLIST.WRI_DESCRIPTION AS [Drawing Title], LastRev.LastOfREVISIONNAME AS Rev, LastDate.LastOfREVISIONDATE AS [Rev Date], WRI_SITE_PRJS.TITLE AS Project
FROM LastRev RIGHT JOIN (LastDate RIGHT JOIN (DRAWINGLIST INNER JOIN WRI_SITE_PRJS ON DRAWINGLIST.WPRJID = WRI_SITE_PRJS.WPRJID) ON LastDate.NAME = DRAWINGLIST.NAME) ON LastRev.NAME = DRAWINGLIST.NAME
ORDER BY DRAWINGLIST.NAME;

I tried getting the same result in SQL and find that I can't GROUP BY the LAST date in a table. The result I'm getting is all the revisions for the drawing.

My question is: How do I query for the LAST date or revision in a table.

I'm using Microsoft SQL Server 2003

Some help is greatly appreciated.
OS

I have never used SQL Server 2003
but i would pressume it would be order by LastDate.LastOfREVISIONDATE DESC
Aug 3 '07 #2

azimmer
Expert 100+
P: 200
I am new to creating SQL queries and need some help.

I am trying to query from three tables.
1 - A table with a list of Drawings (DRAWINGS)
2 - A table with the Revision history of the Drawings (REVISIONS)
3 - A table with the list of Projects (WRI_SITE_PRJS)

The result I am looking for:
Name of Drawing (I want to return the drawings that don't have a revision as well)
Last Drawing Revision
Date of Revision
Project that the drawing belongs on

The below query I created in access and the result was exactly what I was expecting.

SELECT DRAWINGLIST.NAME, DRAWINGLIST.WRI_DESCRIPTION AS [Drawing Title], LastRev.LastOfREVISIONNAME AS Rev, LastDate.LastOfREVISIONDATE AS [Rev Date], WRI_SITE_PRJS.TITLE AS Project
FROM LastRev RIGHT JOIN (LastDate RIGHT JOIN (DRAWINGLIST INNER JOIN WRI_SITE_PRJS ON DRAWINGLIST.WPRJID = WRI_SITE_PRJS.WPRJID) ON LastDate.NAME = DRAWINGLIST.NAME) ON LastRev.NAME = DRAWINGLIST.NAME
ORDER BY DRAWINGLIST.NAME;

I tried getting the same result in SQL and find that I can't GROUP BY the LAST date in a table. The result I'm getting is all the revisions for the drawing.

My question is: How do I query for the LAST date or revision in a table.

I'm using Microsoft SQL Server 2003

Some help is greatly appreciated.
OS
Use Max() on the date column and group by everything else.
Aug 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.