A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

GETTING THE MOST RECENT DATE



 
 
Thread Tools Display Modes
  #1  
Old February 8th, 2007, 03:00 PM posted to microsoft.public.access.queries
bifteki via AccessMonster.com
external usenet poster
 
Posts: 15
Default GETTING THE MOST RECENT DATE

There's a table called tbl_contacts and each contact is related to a company
from the table tbl_companies. I want to get the most recent contact from each
company. Which expression should I use in the fld_contact_date cretiria?

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1

  #2  
Old February 8th, 2007, 03:18 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default GETTING THE MOST RECENT DATE

On what fields are the tables related?
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"bifteki via AccessMonster.com" wrote:

There's a table called tbl_contacts and each contact is related to a company
from the table tbl_companies. I want to get the most recent contact from each
company. Which expression should I use in the fld_contact_date cretiria?

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1


  #3  
Old February 9th, 2007, 09:17 AM posted to microsoft.public.access.queries
bifteki via AccessMonster.com
external usenet poster
 
Posts: 15
Default GETTING THE MOST RECENT DATE

Sorry my mistake I didn't give much info.
They are related on the fld_company_id field (primary key for tbl_companies
and foreign key for tbl_contacts).
The tbl_contacts contains contacts that the company has made with numerous
companies (meaning communicated).

This following query gives the dates of all the contacts of all companies.

SELECT TOP 100 PERCENT dbo.tbl_Companies.fld_company_name, dbo.
tbl_contacts.fld_contact_date
FROM dbo.tbl_Companies INNER JOIN
dbo.tbl_contacts ON dbo.tbl_Companies.fld_company_id =
dbo.tbl_contacts.fld_company_id
ORDER BY dbo.tbl_contacts.fld_contact_date DESC

I want each company to appear one time and I want the date of its most recent
contact appear next to it.
I hope this answers any questions.




Jerry Whittle wrote:
On what fields are the tables related?
There's a table called tbl_contacts and each contact is related to a company
from the table tbl_companies. I want to get the most recent contact from each
company. Which expression should I use in the fld_contact_date cretiria?


--
Message posted via http://www.accessmonster.com

  #4  
Old February 10th, 2007, 03:31 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default GETTING THE MOST RECENT DATE

SELECT dbo.tbl_Companies.fld_company_name,
MAX(dbo.tbl_contacts.fld_contact_date)
FROM dbo.tbl_Companies INNER JOIN dbo.tbl_contacts
ON dbo.tbl_Companies.fld_company_id =
dbo.tbl_contacts.fld_company_id
GROUP BY dbo.tbl_Companies.fld_company_name
ORDER BY dbo.tbl_contacts.fld_contact_date DESC ;
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

"bifteki via AccessMonster.com" wrote:

Sorry my mistake I didn't give much info.
They are related on the fld_company_id field (primary key for tbl_companies
and foreign key for tbl_contacts).
The tbl_contacts contains contacts that the company has made with numerous
companies (meaning communicated).

This following query gives the dates of all the contacts of all companies.

SELECT TOP 100 PERCENT dbo.tbl_Companies.fld_company_name, dbo.
tbl_contacts.fld_contact_date
FROM dbo.tbl_Companies INNER JOIN
dbo.tbl_contacts ON dbo.tbl_Companies.fld_company_id =
dbo.tbl_contacts.fld_company_id
ORDER BY dbo.tbl_contacts.fld_contact_date DESC

I want each company to appear one time and I want the date of its most recent
contact appear next to it.
I hope this answers any questions.

Jerry Whittle wrote:
On what fields are the tables related?
There's a table called tbl_contacts and each contact is related to a company
from the table tbl_companies. I want to get the most recent contact from each
company. Which expression should I use in the fld_contact_date cretiria?


  #5  
Old February 12th, 2007, 07:47 AM posted to microsoft.public.access.queries
bifteki via AccessMonster.com
external usenet poster
 
Posts: 15
Default GETTING THE MOST RECENT DATE

Thank you very much for your reply. However when I enter this statement the
following error appears when I try to save the view:

ADO error: Column name 'dbo.tbl_contacts.fld_contact_date' is invalid in the
ORDER BY clause because it is not contained in either an aggregate function
or the GROUP BY clause.

What could this mean?


Jerry Whittle wrote:
SELECT dbo.tbl_Companies.fld_company_name,
MAX(dbo.tbl_contacts.fld_contact_date)
FROM dbo.tbl_Companies INNER JOIN dbo.tbl_contacts
ON dbo.tbl_Companies.fld_company_id =
dbo.tbl_contacts.fld_company_id
GROUP BY dbo.tbl_Companies.fld_company_name
ORDER BY dbo.tbl_contacts.fld_contact_date DESC ;
Sorry my mistake I didn't give much info.
They are related on the fld_company_id field (primary key for tbl_companies

[quoted text clipped - 19 lines]
from the table tbl_companies. I want to get the most recent contact from each
company. Which expression should I use in the fld_contact_date cretiria?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1

  #6  
Old February 13th, 2007, 12:26 AM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default GETTING THE MOST RECENT DATE

Try removing the last line.

Also do you really need the dbo. on everything? Is this a simple query or
something that you are running from code.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"bifteki via AccessMonster.com" wrote:

Thank you very much for your reply. However when I enter this statement the
following error appears when I try to save the view:

ADO error: Column name 'dbo.tbl_contacts.fld_contact_date' is invalid in the
ORDER BY clause because it is not contained in either an aggregate function
or the GROUP BY clause.

What could this mean?


Jerry Whittle wrote:
SELECT dbo.tbl_Companies.fld_company_name,
MAX(dbo.tbl_contacts.fld_contact_date)
FROM dbo.tbl_Companies INNER JOIN dbo.tbl_contacts
ON dbo.tbl_Companies.fld_company_id =
dbo.tbl_contacts.fld_company_id
GROUP BY dbo.tbl_Companies.fld_company_name
ORDER BY dbo.tbl_contacts.fld_contact_date DESC ;
Sorry my mistake I didn't give much info.
They are related on the fld_company_id field (primary key for tbl_companies

[quoted text clipped - 19 lines]
from the table tbl_companies. I want to get the most recent contact from each
company. Which expression should I use in the fld_contact_date cretiria?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1


  #7  
Old February 13th, 2007, 07:30 AM posted to microsoft.public.access.queries
bifteki via AccessMonster.com
external usenet poster
 
Posts: 15
Default GETTING THE MOST RECENT DATE

Thanks a lot! It works !
The thing is I made the original simple query using the diagram and grid
panes and copied the statement from the SQL pane. So I guess Access used this
naming in the query by itself.
Thanks again!!!


Jerry Whittle wrote:
Try removing the last line.

Also do you really need the dbo. on everything? Is this a simple query or
something that you are running from code.
Thank you very much for your reply. However when I enter this statement the
following error appears when I try to save the view:

[quoted text clipped - 17 lines]
from the table tbl_companies. I want to get the most recent contact from each
company. Which expression should I use in the fld_contact_date cretiria?


--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:41 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.