need a query to get the values corresponding to latest dates

Hello everyone,

Briefly stated, I have a table structured like:

VariableName (string)   Value (double)   Date (date)

Variable names can be repeated (don't worry, in the actual table I
have index numbers that call up the variable names from another
table), so this table contains a limited number of variables' values
that can change independently.

I am using two queries that work together to give the values
corresponding to the latest dates. One query groups by VariableName's
and uses Max(Date) aggregate function to get the latest date, then the
second query joins the first query with the table once again to find
the values corresponding to the latest dates found in the first query.

If all these have made any sense, can anyone tell me a way to
accomplish the same thing in a single query? Joining this table with a
second copy of itself did not help. Not a big deal, but I thought
there might be a simple solution.

Thanks for anyone's time for even reading this.

Take care,
Hurol

0
gobis
5/17/2007 9:07:23 AM
access.queries 6343 articles. 1 followers. Follow

1 Replies
1282 Views

Similar Articles

[PageSpeed] 17

One method use a coordinated sub-query

SELECT VariableName, Value, Date
FROM Table
WHERE Date =
   (SELECT Max(Date)
    FROM Table as Temp
    WHERE Temp.VariableName = Table.VariableName)

Another method uses a sub-query in the from clause
SELECT VariableName, Value, Date
FROM Table INNER JOIN
   (SELECT VariableName, Max(Date) as TheLast
    FROM Table
    GROUP BY VariableName) as TEMP
ON Table.VariableName = Temp.VariableName
And Table.Date = Temp.TheLast



-- 
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"gobis" <hurol_aslan@mersin.edu.tr> wrote in message 
news:1179392843.238877.307190@w5g2000hsg.googlegroups.com...
> Hello everyone,
>
> Briefly stated, I have a table structured like:
>
> VariableName (string)   Value (double)   Date (date)
>
> Variable names can be repeated (don't worry, in the actual table I
> have index numbers that call up the variable names from another
> table), so this table contains a limited number of variables' values
> that can change independently.
>
> I am using two queries that work together to give the values
> corresponding to the latest dates. One query groups by VariableName's
> and uses Max(Date) aggregate function to get the latest date, then the
> second query joins the first query with the table once again to find
> the values corresponding to the latest dates found in the first query.
>
> If all these have made any sense, can anyone tell me a way to
> accomplish the same thing in a single query? Joining this table with a
> second copy of itself did not help. Not a big deal, but I thought
> there might be a simple solution.
>
> Thanks for anyone's time for even reading this.
>
> Take care,
> Hurol
> 


1
John
5/17/2007 11:36:27 AM
Reply:

Similar Artilces:

Not sure if Excel can do what i need
Hello all, I am obviously a new user to excel. I have a psychological assessmen that needs to be computerised for ease of use in obtaining results. Here is what i would like to happen. I have 28 questions with fiv Likert scale options(0-4) for answers. Each question addresses 1 of different personality traits. So questions 1, 6, 8, 22 look at anger. Where as questions 2, 9, 28 look at happiness. What i would like is fo excel to group the answers and give me the total number for each trait. Then based on that number, give out a prewritten (which i would provide result of the assessment. ...

Graph
Hi, Here is the problem - There is a graph I have to create, based on the following information: I have projects names, and each project has the following data: 1. Estimated cost. 2. Actual cost. 3.Status, which can be one of 3: a. over with b. in progress c. per demand I need to put the data on a 3D column graph, in a way that each project will have 2 columns that compare estimated and actual cost, but the problem is I also need to put some kind of an attribute on every project which reflects its status. How do I do that? Thanks in advance, Chen. Chen - I'd suggest a 2D chart type in...

Text Values #2
I'm tryng to build a spreadsheet to track employee vacations. How do I sum 8 hours if a cell has a "V" entered and 4 hours if a cell has an "X" entered? Assuming you're using column A, and each row is either the number of hours worked, or a V or a X, then use a helper column, B, and insert this in B1 and copy down.......change the A1's to A2's if you have a header in Row 1, and put this in B2. =IF(A1="V",8,IF(A1="X",4,A1)) Vaya con Dios, Chuck, CABGx3 "Brando" <carpenterchsd@earthlink.net> wrote in message news:1113...

Need Min Value from Row and Heading Value that Corresponds to it.
I have a table that looks somewhat like this w/o the *'d headings: h1 h2 h3 h4 h5 h6 h7 *Min Price *Heading $5.00 $6.00 $3.00 $4.00 $9.00 $1.00 $9.00 $1.00 h6 $3.00 $6.00 $8.00 $65.00 $9.00 $2.00 $4.00 $2.00 h6 $4.00 $9.00 $5.00 $7.00 $1.00 $2.00 $8.00 $1.00 h5 $9.00 $7.00 $6.00 $3.00 $9.00 $8.00 $2.00 $2.00 h7 $7.00 $8.00 $9.00 $7.00 $9.00 $8.00 $8.00 $7.00 h1 I have several SKU's with various price contract/programs. I want to find the best price in one cell and the heading that would correspond to that cell in another. I was trying to do this with an expression ...

Match value in one column and return value in same row in next col
Hi, I have a a set of values in A1 through A100. I need to look up each value and find a match in another set of values located in C1 through C200. If a match is found then I need the formula located in column B to return the value in the same row but the next column over (D). Example: A B C D 359 375 10012 456 125 10031 125 10031 952 10052 854 444 10017 The formula located in B3 should find that the value of 125 (located in A3) matches the value in C2 and returns 10031 which is the v...

Date shows as 01/01/00
We have a spreadsheet that we want to enter a date in a cell. I have changed the format to Date 03/01/01 format but no matter what I do, any date is converted to 01/01/00. I have tried inserting a column, copying to another spreadsheet, etc. I know this is probably simple, but it's driving me crazy. Help please. In an un-used cell enter: =TODAY() if this is not the correct date, then touch CNTRL-ALT-F9 on the keyboard post what happens. -- Gary''s Student "Kmagg" wrote: > We have a spreadsheet that we want to enter a date in a cell. I have changed > the...

Excel need help
I have 2 columns a and b . a contains payment b contains balance. I have the entire col b with the formula. my ? is when the balance appearsin b it is in all the cells in that column.I only want it in the used ones, not the unused ones:( example $270.00 16,730.00 $270.00 16,460.00 $100.00 16,360.00 $300.00 16,060.00 $270.00 15,790.00 15,790.00 15,790.00 15,790.00 15,790.00 15,790.00 this 15790.00 is in col b...not a...I want no bal in unused cells -- fiftieslady ------------------------------------------------------------------------ fiftieslady's Profile: http://www.excelforum.co...

How do I Excel formula =LEFT(A2,LEN(A2)-3) in an Access Query
I need to delete the last 12 characters (phone number) from a field that contains names and phone numbers. Lou Are you asking how to do this in MS Access? If so, take a look in Access HELP re: Mid() function and Len() function. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. ...

Help with IF stament (getting result FALSE in some cases)
Good morning everyone. I have the following calculation that is causing me a problem =IF(G109<70%,SUM(G90-G96)*AVERAGE('Base Data'!$I$31:$I$35,IF(G109>70.01%<99.99%,SUM(G90-G96)*AVERAGE('Base Data'!$H$31:$H$35,IF(G109>100%,SUM(G90-G96)*AVERAGE('Base Data'!$G$31:$G$35)))))) The 1st part of the formula (<70% ) is working and returning a value. However if the % is greater than 70% I am getting the result FALSE I'm sure it's a simple fix but cannot put my finger on it Any help greatly appreciated, Thanks Hi Mark, Apart f...

New Address type picklist value not appearing in picklist on forms
Hi, I've customized my Customer Address form to add a new AddressType value of "Registered Office"; value is 6 and I can see it when I go into the form customization editor. However, when I try to add a new address to, say, a Contact, this new address type value isn't shown. Ditto if I attempt to edit an existing address. What am I doing wrong? Thanks. -- Michael Mayne Did you publish the forms and then issue an IISRESET? Matt Parks MVP - Microsoft CRM ---------------------------------------- ---------------------------------------- On Wed, 1 Dec 2004 10:21:04 -0800, ...

Need Help Linking Sheets
How can I link 2 pages without using the actual sheet as a reference? In other words, can I have two sheets linked by Identifying the same exact names one on each sheet? ...

Excel newbie needs help from math wiz (poker related)
I want to create a Excel workbook that will help in specific poker situations. Short version: I want to be able to calculate how often my opponent will need to fold for an all-in raise to show a positive expectation. Explanation: In poker you can win a hand by having the best hand at the end OR getting your opponent to fold. A common situation comes up where you have a "drawing hand" and face a bet by your opponent. In this situation you know you are currently behind in the hand, but have a chance to win if you catch some of your "outs" (cards that will give you th...

Date Format Conversion?
I have a tab delimited text file with a column of dates. I copied and pasted a selection of them below as a reference, there are in reality over 35,000 rows of these dates. These text dates must be converted to the following date format and saved back into a text file as such: mm/dd/yyyy That includes leading zeroes in months and dates. E.g. 01/01/1999 To complicate matters, I need to explain the process to others. Does anyone even know where I should begin? THANK YOU, - Chris +++++++++++++++++++++++++++ 9031989 8131990 9201989 1271990 10291989 1081990 3041990 10051989 4191990 10...

Macro help needed........
How do I sort a particular column in ascending order and change the pag setup to landscape and margins to 0.25 using a macro code ? does anyone have a macro code for this ????? -- Message posted from http://www.ExcelForum.com Hi you have already received some answers in your previous threads please don't multipost! -- Regards Frank Kabel Frankfurt, Germany > How do I sort a particular column in ascending order and change the > page setup to landscape and margins to 0.25 using a macro code ? > > does anyone have a macro code for this ?????? > > > --- > Me...

Query to update new fields in table
I added two fields to a table a date field and a Day field. The table already had approximately 40,000 records. Is there a query I can use that will add the date and day to the already existing data. I know moving forward I can get update with an append query. An Update query will update existing fields. Just choose the fields you want to update, and put the data in the row marked Update to, and you are good to go. CS wrote: > I added two fields to a table a date field and a Day field. The table > already had approximately 40,000 records. Is there a query I can use that >...

Need to test a mobo
I had a power surge about 3 weeks ago - lost a drive, now making ticking noises. I had another two drive that seem to work sporadically now. So, I thought it might have been my power supply. Bought a tester and found out that all seems well. Next, I bought a new hard drive and found that it was also acting up - making noises like whirring up and down (like the other drives I thought were dead). So I am starting to wonder if it is my mobo - but how can I test this out? I am using a dual boot - Win XP and Win 7 - both drives work and don't work. Up and down. Right now my Win7 ...

Lost formatting in Query
I have a query based off of a table, with a subdatasheet pulling from a separate table. I've been using this system for approximately 3 years with no problems. However, within the last few months, I've had a problem with the formatting being lost each morning. I'm constantly having to re-insert the subdatasheet and re-size all my columns that have gone back to the default width. I've never had this problem until recently. My solution so far has included a compact and repair, and to re-design the entire query from scratch. Neither have solved the problem. As another...

how to bind an query to a gridview programmatically?
Hi, i want to bind programmatically the records of a select query to an existing gridview. I can get the records via dtreader, but i don't know how to get them into the gridview (which is created in the aspx file) Thanks Luc My attempt: connectionstr = ConfigurationManager.ConnectionStrings("myconn").ConnectionString.ToString() connection = New SqlConnection(connectionstr) comd = New SqlCommand() comd.Connection = connection comd.CommandText = "select field1 from table1" connection.Open() dtreader = comd.ExecuteReader If dtreader.HasRows Then...

Get complete email message source from Outlook 2003???
Hello! I need to be able to simply copy/paste the COMPLETE source data from an email message recieved in Outlook 2003. I know I can get headers by using Options, but I need the complete message. In Outlook Express this is very easy. Select the message, view Properties, Details, Message Source button... Voila! I don't see how Microsoft could omit this in Outlook 2003! http://www.outlook-tips.net/howto/view_source.htm -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Outlook Tips: http://www...

Help needed
is there anyway you can see what links to other workbooks are associated with the workbook you have open. The problem i am having is when i open the workbook in question a message appears and states "The workbook you opened contains automatic links to information in another workbook. do you want to update this workbook with changes made to the other workbook" Yes....... No. if i click No the workbook opens, however if i click Yes the workbook just hangs and i have to go into task manager to shut down the system. I can only assume that there is a problem with one of the links....

Need help on this....thanks
I have an Excel worksheet which stored a survey outcome of over 1200 members. There are over 30 questions in the survey and the first column captured the member ID. The problem is 3 of the survey questions that allow multiple answers, instead the answer for those three questions are captured in seperate column, the answers are stored in a single column and it makes it very difficult to analysis those result. As a result I created addittional columns depending on the total number of the answers available for that question and assign the result manually to that column. It is very time consuming ...

How to access Customer Due Date for current transaction
Hi Everyone ? I am looking to display payment due date on the invoice for my customer when the tender type is store account Currently I have 2 type of due date : 14 days and 30 days So for example if invoice date is today 1 Sept 2010. I need to print the due date as 15 Sept 2010 How can I access the customer account due date in receipt ? I tried Customer.AccountDueDateType and I got error "token not found" anyone has an idea ? Thank you, Regards, Joie ...

how do i get my currect email account onto microsoft outlook?
i just deleted my trial of microsoft office. Now I have microsoft office xp with front page. i can't figure out how to get my email account set up on outlook. i have cable internet service. Please Help!!! acrowl <acrowl@discussions.microsoft.com> wrote: > i just deleted my trial of microsoft office. Now I have microsoft > office xp with front page. i can't figure out how to get my email > account set up on outlook. i have cable internet service. Please > Help!!! Your cable company can tell you that. It's usually a POP account so start with Control Panel>...

I need Help
I have a random popup that i cant stop,when it does come up it seems to know what i was looking at,like when i was looking for registry cleaner it popped up and showed me one,any help would be great. On Jan 22, 6:57=A0am, Larry <La...@discussions.microsoft.com> wrote: > I have a random popup that i cant stop,when it does come up it seems to k= now > what i was looking at,like when i was looking for registry cleaner it pop= ped > up and showed me one,any help would be great. To eliminate questions and guessing, please provide additional information about your sys...

need help badly
How do you print ole objects.. Thanks lachanda -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200710/1 On Wed, 03 Oct 2007 18:13:40 GMT, "misschanda via AccessMonster.com" <u36612@uwe> wrote: >How do you print ole objects.. >Thanks >lachanda What *kind* of OLE objects? Many of them are binary blobs (such as programs) which are inherently not printable. More details please! John W. Vinson [MVP] ...