473,396 Members | 1,891 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.

Query for Last Date in a table

oszapped
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
2 7615
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
200 Expert 100+
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

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

Similar topics

3
by: Pakku | last post by:
This is on DB2 V7 on OS/390 I have 2 tables PATIENT and SPECIMEN. PATIENT columns are IDENTIFICATION LAST NAME FIRST NAME SPECIMEN columns are SPECIMEN_NUMBER (this is a manufactured...
2
by: Willem | last post by:
Hi there, I'm sort of new with doing much record manipulation with queries. Up till now I've been programming VBA and doing record looping to get my results. This works fine but tends to get...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
3
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance you can provide. I have a table in an Access 2000 .mdb file, and I've run into something odd and insolvable, at least for me. The database is...
2
by: dauwe.peter | last post by:
A table : Nameperson, Book nr, Bookdatein, Bookdateout, CD nr, cddatein, cddateout, dvd nr, dvddatein, dvddateout. I would like a query where a see the personsname en de last book with the...
1
by: bruce24444 | last post by:
First of all I'm new to the forum and am working on my first database. So far I think I've done not too bad but have hit a stumbling block for which I'm not sure how to get around. What I have is...
4
by: kdubble | last post by:
Hi I am trying to get the results of a query to show only unique student records (not duplicates). Is there a simple way to make the criteria field do this? I am not too familiar with SQL. ...
2
by: scott | last post by:
Hi Everyone, I have a table which has many fields in it but I need to pull some specific info via a query and I don't know if it's possible. I want to run a query which includes two tables....
12
by: Michel Esber | last post by:
Hello, Db2 Linux LUW FP 15. Consider table A (ID varchar, EXECUTION_DATE date). a) I want to first retrieve all IDs that have not executed during the last 90 days: select distinct ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...

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.