Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find most recent version of record without n-square query

Status
Not open for further replies.

DJUrsus

Programmer
Sep 15, 2003
2
US
I have 4 tables each with a text primary key (name), and each of them is a different age. I have imported them all, oldest to newest, into another table. The new table has a numeric incremental key (ID), so the old entries have lower IDs. I want to produce a table of only the newest versions of each record. I have a query that does it:
Code:
SELECT *
FROM Customers
WHERE ID IN (SELECT MAX(ID)
             FROM Customers
             GROUP BY name);
The problem is that it runs the ^%$# sub-query every time, and takes a &^%$ day and a half to run the query. Anybody got some ideas? Thanks!
 
I don't know if I understood correctly but why don't you
try this

select customerID, CustomerName, etc.., max(ID) from customers group by customerID


This should return newest information about each separate customer.

Bye

Qatqat

Life is what happens when you are making other plans.
 
Unfortunately, it won't let me grab anything but name and ID while grouping and maxing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top