Query To Get Only Latest Entries

Feb 26, 2007

I am having difficulty formulating this query.

I have 2 tables... 1 is customer info (name, address, etc...), and the second is shipments (ShipToCustomerName, ShipmentDate, etc...).

Now, I wish to query the shipments table to get ONLY the LATEST shipment information for EACH customer.

If customer A has a shipment in Jan 1, Feb 2, and March 3... while customer B has a shipment in April 4 and May 5. then the result of the query should be

customer A - March 3
customer B - May 5

Is there a simple way to construct such a query?!?

Thank you for your help,

- arm

View Replies


ADVERTISEMENT

Show Latest Entry Of Multiple Entries

May 25, 2005

I am trying to customize one of my query table, so that it shows the latest review date of an employee (with multiple entries). I have gotten the SQL statement to work so that it shows the latest employee review date which is greater than the current date. But if the employee has 2 records after the current date and I want it to show the latest entry of the 2. I don't know to put add a sub-Select statement or whether to add another criteria in the Where criteria.





e.g. Current Date = May 25, 2005If Employee A's next review date is set for June 1, 2005 but has already been reviewed (the next review date is May 31, 2006). The query will show the June 1, 2005 and not the latest entry of May 31, 2006.


Because there are 2 review dates that are after the current date. What should I do to make only the latest entry appear?


Below is the my VBA code so far, which produces the above result.



SELECT tblEmp.fname, tblEmp.lname, tblEmpWorkHistory.[current store], tblEmp.position, tblEmpSalaryHistory.salary, tblEmpSalaryHistory.next_review_date
FROM (tblEmp INNER JOIN tblEmpSalaryHistory ON tblEmp.ssn=tblEmpSalaryHistory.ssn) LEFT JOIN tblEmpWorkHistory ON tblEmp.ssn=tblEmpWorkHistory.ssn
WHERE (((tblEmpSalaryHistory.next_review_date)>Now() And (tblEmpSalaryHistory.next_review_date)<=[Please enter the Next Review Date]))
ORDER BY tblEmpSalaryHistory.next_review_date;

My brain is stuck and can't figure it out. I hope any fresh mind could help me out. Thanks in advance.

View 5 Replies View Related

Query Only Latest Info

Sep 7, 2005

How do I make an append query only append the records beginning with the next autonumber?

I have linked tables in db...one db is for warehouse employees to input their orders and the other table is in the original db for managers to use for reports. I need to append the records to original db throughout the day, but the records cannot be deleted from warehouse db because it keeps running total of order minutes (for production purposes) so employees know how many minutes they have (and need to make up) through the day. Also, managers need up to date db so they can see if they are on track.

The autonumber field is my primary key..
I hope this all makes sense.

Thanks in advance
Noreene

View 3 Replies View Related

Query Latest User

Sep 11, 2006

Hi,

I am working on a report and I am stuck with the following problem:

Here at work we use two tables. One for creating records and for the updates of the created records. In the attachment you see a part of the table 'updated'. What you see is one ServiceNumber (1-551747091) which is changed users (Eigenaar.) three times.

I want to query the latest user of each ServiceNumber. So that the result is:

ServiceNumber | User
1-551747091 | MKB_VERHUIZEN
etc.

How to do that? :confused:

Thanks!

View 3 Replies View Related

Query Based On Latest Time

Apr 7, 2007

I have two fields. A barcode field will have several instances of the same data, and the other field has different dates and times when it was scanned. I need to be able to query the barcode field and only return the record with the latest time. Can this be done in a query or do I need to do something else? Here is a sample of data I am working with. I attached a small sample of data as an example.


Thanks,

View 3 Replies View Related

Find Latest Record With Query

Aug 22, 2007

I'm fairly new to SQL and have a problem finding the latest record.

Lets say I have a development project that has many disbursal payments to be sent. I want to find the latest disbursal record created for that one project instead of having all of the disbursal records show on the query.

I'm trying to work out how to do this in a query but haven't got a clue where to start.

Please, if anyone can help I'd be very grateful!:D

View 2 Replies View Related

Pick Latest Record From Query?

Dec 16, 2005

I am trying to pick the latest record from "tblEmpVac.id" field but I keep getting syntax errors. I am thinking if the "tblEmpVac.id" = Count('tblEmpVac.id') then that will show the most current record as it will count and match the last record correct?

Another problem is if I put it into the WHERE section, it will give a conflict. So I don't know where to put it. Below is the SQL, if anyone can help it would be great.


SELECT DISTINCTROW tblEmp.position, tblEmp.fname, tblEmp.lname, tblEmpWorkHistory.region, tblEmpWorkHistory.[current store], tblEmpVac.current_year, tblEmpVac.id, tblEmpVac.entitlement, tblEmpVac.days_taken, tblEmpVac.days_carryover, [days_carryover]+[entitlement]-[days_taken] AS total
FROM ((tblEmp INNER JOIN tblEmpVac ON tblEmp.ssn = tblEmpVac.ssn) INNER JOIN tblEmpWorkHistory ON tblEmp.ssn = tblEmpWorkHistory.ssn) INNER JOIN tblEmpWorkHistoryData ON tblEmpWorkHistory.ewh_id = tblEmpWorkHistoryData.ewh_id
WHERE (((tblEmp.position)<>"Terminated") AND ((tblEmpVac.current_year)="2005"))
ORDER BY tblEmp.position, tblEmpWorkHistory.region, tblEmpVac.id;

View 2 Replies View Related

Show Only Latest Note Entry In Query

Jan 13, 2008

Two of the fields in my query are for Progress Note and Progress Note Date. Each client has several progress notes. How can I have the query show only the Progress Note with the latest date?

:confused:

View 9 Replies View Related

Select Query For Latest Previous Date

Oct 2, 2006

My table shows
ID ID_Clients EndDate

A particular value of ID_Clients can recur many times, but with different EndDate value each time.

I want to create a select query that displays
ID_Clients EndDate LatestPreviousEndDate

Any help with this would be much appreciated.

-Thanks

View 1 Replies View Related

Queries :: Query To Show Latest Date

May 29, 2014

I have two tables. The first is called Drawing Register and contains the fields Drawing No (primary field) and Drawing Title.The second table is the Drawing Register Details table which contains the fields Drawing No (joined field - Drawing Register table), Revision, Revision Notes, Date Issued.

I have a query and report which will list all the revisions for each drawing. This is very important and useful. However I want a summary report which will only show the last revision for each drawing.

I copied the original query, turned on the Totals option and under the Date Issued field changed Group by to Max. However it is still returning all results for each drawing instead of only the last issue date for each drawing.

View 14 Replies View Related

Queries :: Finding Latest Number Using A Query

Jun 19, 2013

I need to find the latest number using a query.

All of the numbers follow this format:

[Doc No]
ABCD123

but the tricky part is the number could be suffixed with a revision. It is the latest revision I would like to find. For example, If I have a number followed by 3 revisions I would have:

[Doc No]
ABCD123
ABCD123+200
ABCD123+300
ABCD123+400

I need a query to give me the latest revision, in this case

[Doc No]
ABCD123+400

There is a possibility there are no revisions in which case the latest will be

[Doc No]
ABCD123.

How is this possible in a query???

View 5 Replies View Related

Queries :: Getting Latest Record For A Particular Customer Number Using MS SQL Query

Jul 27, 2013

My table appears like this with the following columns:

Name| CUSTNo| ORderNo.| AcctDate| OrderDate| OrderDescription

I would like to write a ms-sql query to return the records of each customer number with the latest OrderDate. One more thing, if the customer has two separate order numbers on the same date(should be the latest date), the query should be able to pull up both the records.

I tried with the code below but its taking a long time to execute and finally hanging up MS ACCESS.

SELECT * FROM TableName AS a WHERE Not Exists (SELECT *
FROM TableName b WHERE b.CUSTNo = a.CUSTNo AND b.OrderDate >= a.OrderDate);

View 2 Replies View Related

Queries :: Latest Date Per FName - Query From Table

Nov 23, 2014

How do I query from this table:

ORIGINAL_table

FName | END_Date|
--------|---------------|
John| Oct 09, 2014|
John| Oct 15, 2014|
John| Oct 25, 2014|
Mike| Dec 10, 2014|
Mike| Dec 15, 2014|
Mike| Dec 20, 2014|
Mike| Dec 25, 2014|
Jimm| Dec 10, 2014|
Jimm| Dec 15, 2014|
Jimm| Dec 20, 2014|
Alex| Dec 01, 2014|
Alex| Dec 05, 2014|
Alex| Dec 10, 2014|
Thom| Nov 10, 2014|
Thom| Oct 10, 2014|
Thom| Aug 10, 2014|

The output will be:

FName | END_Date|
----------|---------------|

John| Oct 25, 2014|
Mike| Dec 25, 2014|
Jimm| Dec 20, 2014|
Alex| Dec 10, 2014|
Thom| Nov 10, 2014|

The query table(output) will just have to be latest date("END_Date") per "FName"

View 1 Replies View Related

Queries :: Query Result For Latest And Max Date From Table

Apr 26, 2013

I try to make a query that can show me data from the lastest and max date from the table i have ( see attchment file )

I try using max but still the result is not what i am looking for...

View 6 Replies View Related

Queries :: Subquery To Return Latest / Most Recent Value For Each Record In Main Query

May 7, 2014

I have a table of accounts and a table of rates. There is a one-to-many relationship between them (i.e. each account can have multiple rates, each with their own - unique - effective date)

I'm trying to build a query which will show me all of the accounts in the accounts table and the most recent rate (based on the effective date) for each of those accounts.

This is as far as I've gotten with the SQL :

Code:
SELECT [tblAccounts].[AccountID], [tblAccounts].[AccountNumber], [tblAccounts].[AccountName], [LatestRate].[IntRate], [LatestRate].[EffectiveDate]
FROM [tblAccounts]
LEFT JOIN
(SELECT TOP 1 [tblRates].[AccountID], [tblRates].[IntRate], [tblRates].[EffectiveDate]
FROM [tblRates]
ORDER BY [tblRates].[EffectiveDate] DESC) AS LatestRate
ON [tblAccounts].[AccountID] = [LatestRate].[AccountID]

But this can't work because the [LatestRate] subquery can only ever return one record (i.e. the most recent rate across all of the accounts)

I need the most recent rate for each of the accounts in the main query

(FYI - I use an outer join as it is possible for no rate to be available in the rates table for a given account, in which case I want to return the null value rather than omit the account from the resulting dataset...)

View 2 Replies View Related

Creating Two Tables - Old Entries And Weekly New Entries?

Mar 13, 2014

I have a table in access which is updated weekly; I need to create two tables from this updated table.

1st table will consist of all the new entries for the current week

2nd table will consist of all the entries from the previous week - an amalgamation of all the entries which are not from the "current week" (table) For example; the table below shows the two entries from last week.

ID
Name

1
Adam

2
Ben

This week I have three new entries New entries

ID
Name

3
Charles

4
Richard

So when I run the same query next week I will get something like this.

Old Entries
ID
Name

1
Adam

2
Ben

3
Charles

4
Richard

[code]....

How do I get a query /queries which divides up the weeks new entries and also all the old entries.

View 11 Replies View Related

IIF In Query Q - Listing All Entries

Jun 20, 2006

Hello,

I currently have a DB that has a field in a table that records which shift (A, B, or C) that some data was collected on. I am trying to write a Query in order to filter the results so that either the data from shifts A,B, or C show up, or if "All Shifts" is selected, then all the data shows up. I have another table set up that records the shift selection from a form. I was trying to use an Iif statement but it does not seem to be working for the "All Shifts" option. Selecting "Shift A" or "Shift B" etc. works fine.

IIf([ShiftSelect]="All Shifts","Shift [ABC]",[ShiftSelect])

**[ShiftSelect] containts the users selection for which shift they want to view.

I have also tried this with a wildcard statement (Like "*") instead of "Shift [ABC]", to see if I could get any data to show but I still get nothing when "All Shifts" is selected!

Let me know if you can see the problem, or know another way to go about this query!

View 2 Replies View Related

Query Multiple Entries?

Sep 12, 2006

Hi Folks,

I was just wondering if its possible, i'm sure it is.......
I've got a query to pull out invoices for a certain Project it brings up all project invoices and puts it into a report which works fine...... what i want to do tho is perform the same query but after i type in project code in criteria [] i then want to type peoples name or ID's that i want to print as some will be sent at different time intervals and i don't want to have to sort through invoice's to then send? is it possible? any one got any examples?

Thanks in Advance

View 1 Replies View Related

Locating Multiple Entries In Query

Mar 3, 2006

Hello, I have searched the forums and found plenty of information about eliminating duplicate values. What I would like to be able to do is run a query and have it show me only the records that have the field "serial number" that contain the same number. That is, I want to be able to query and see which serial numbers have been entered more than one time. The serial number is not the primary key, this database keeps track of product repairs and is used to log them in by the primary key serial number/date. Thanks in advance for any help. Tim

View 2 Replies View Related

Multiple Entries Using Append Query

Aug 1, 2006

Hi all
Can someone help me with an Append query problem I am having. The end result I need is a Work sheet that has a Customers details, Plant details, Work required and a Subcontractor name. I have a search function that I use to select either a Customer name or Plant ID. Once I have selected the Customer name/Plant ID, I use a button to append the Customer Name and the Plant Id to a Plant_History table. This table uses an Autonumber field to create a unique identifier for each entry which I am using as the Work Sheet number. I have then added coding to open a form which accesses the Plant_History table directly so I can enter the work required and the contractor to carry out the work.
My problem is that the Customer and/or Plant will have multiple entries in the Plant_History table. Currently, when I select the button to append the details to the Plant_History table, if the Plant ID is already in the table, the number of records is doubled in the Plant_History table (eg if the record has previously been entered 4 times, 8 records will be appended to the table). I am not sure why this happens, if someone could point out the fault in my work, it would be much appreciated.
Regards
Craig

View 1 Replies View Related

Queries :: Query With IIF And Null Entries

Jul 29, 2013

I have a form that feeds information to a query which in turn sets up a report. For clarity i will list out in basic terms what I have

Input Form
- Check Box to activate/De-activate a text field [chk-active]
- Text field for a parameter [txt-Parameter]

the query has a column that has null values from the originating table. These values will be added a t a later date, but need to be queried and reported at some business intervals.

In the query criteria for this column, I have the following Criteria

Like IIF([Forms]![ReportGenerator]![chk-Active]=0, "*", [Forms]![ReportGenerator]![txt-Parameter])[/I][/I]

I have tried for the last 5 hours to figure out how to write the formula to be able to get the blank entries to show up as well but have had no luck.

View 5 Replies View Related

Append Query Problem, Wont Add Entries

Jul 30, 2007

I am trying to add data to the same column which is in multiple tables at once by running a macro that has multiple queries. I run a macro, and the first is a delete macro, which deletes the column and then the next is an append query which then adds the new column wtih the new data....and it works, for adding it to one table. But when I try to do this for updating two tables from the one macro (using 4 queries, 2 add, 2 delete), I get the usual warning messages "you are about to add/delete 10 entries, and this is for the first table, so i just lclick "ok" "ok" and then i get the message "you are about to delete 10 entries" for the 2nd table, PROBLEM IS THEN I Get message "You are about to append 0 entries" IT SHOULD BE APPEND 10, its the exact same query setup.....it deletes them from all the tables, but then it will not add them to the 2nd, 3rd, 4th table etc etc.....it keeps saying "will append 0 entries" PLEASE HELP, otherwise im screwd lol.

View 1 Replies View Related

Create Query That Removes Any Entries With More Then 5 Digits?

Nov 14, 2007

Hi,
I'm trying to import data from another database (codes), and the text field in that database is set to 7.

Our new database only needs the first 5 digits of the codes, so I'm wondering is it possible to create a query that filters any entries where the code field has more then 5 digits?

View 12 Replies View Related

Remove Duplicate Entries In Query Design

Oct 27, 2013

I am attempting to filter the data in query design such that it will not return anyone in the database has there name present more than one time.

For example, in the image below under the Owner_Name field there is "Abbot, Mark C Etux Wanda C". This name appears twice in the database. My criteria is the name can only appear once, therefore this record would not be returned after the query. In query design I would like it to return only name records that appear once in the entire database if there is a way to structure that.

View 1 Replies View Related

Inlcuding Multiple Identical Entries In Union Query

Oct 4, 2007

I have two tables: tblOne and tblTwo with identical categories.
TblOne and tblTwo both group by Category and Duration. When I make a union query between tblOne and tblTwo, I notice that if I have the exact same category and duration for BOTH tblOne and tblTwo, the union query "eats up" one of the identical entries. How can I fix this?

I need to have two different tables because they correspond to two different machines (but are both the same type of machine, hence the identical categories)

View 1 Replies View Related

Removing Duplicate Entries From Joined Tables In CrossTab Query?

Jun 19, 2007

Hello all,

I have made a crosstab query that is sporatically making duplicate counts. I'd like to know how to fix the problem, but more importantly - I'd like to know why and how my query is giving me these results so I can avoid making this same mistake again.

The relationship is set up so that all records from one table are returned, with only matching records from the other - so no problems that way as far as I can see. This is my crosstab query that is giving some counts of the same record as being matched sometimes two, three, or even four times:

TRANSFORM
Count([Testing DB].[DB_ID]) AS [CountOfDB_ID]

SELECT
[Testing DB].State, [Location].[North], Count([Testing DB].[DB_ID])
AS [Total Of DB_ID]

FROM [Testing DB] LEFT JOIN [Location] ON [Testing DB].[Address] = [Location].Address

WHERE (([Testing DB].[Window Length]) Is Not Null))

GROUP BY [Testing DB].State, [Location].[Size]

ORDER BY [Testing DB].State, [Location].[Size]

PIVOT Format([Date],"mmm-yyyy");

When I do a simple query for a list of the records being counted by this query, I can see the duplicate entries and can eliminate them simply by adding "Distinct" to the select statement - but I haven't had any luck adding any kind of distinction with this crosstab that will do the same.

How can I eliminate duplicate counts of records in my crosstab? If anyone has a suggestion, it would be much appreciated.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved