Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Expression times out when running query

Posted on 2008-10-02
4
Medium Priority
?
168 Views
Last Modified: 2010-03-20
I am trying to get the maximum date for each record.  There are numerous records for each NDC and I need to get the NDC record which has the maximum time stamp for each different NDC how can I do this without the expression timeing out.

thanks
SELECT     r.NPT_PRICEx, r.NDC, r.NPT_DATEC
FROM         RNP2 r INNER JOIN
                          (SELECT     MAX(npt_datec) AS maxbbdc, NDC
                            FROM          rnp2
                            GROUP BY NDC) a ON r.NDC = a.NDC AND r.NPT_DATEC = a.maxbbdc
WHERE     (r.NPT_TYPE = '01')

Open in new window

0
Comment
Question by:running32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 1000 total points
ID: 22627799
do you have an index on npt_datec that covers ndc?

ance since you are filtering on r.npt_type, you should put the same criteria on the inner select between "from rnp2" and the group by.
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 22627805
do you have an index on the field NDC + NPT_DATEC ?
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22627858
wrong use of words... should have been "and" and not "that covers"


0
 

Author Comment

by:running32
ID: 22628272
thank you
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question