Jump to content

Returning first row in a table for multiple items...


Yammyguy

Recommended Posts

Hello all,

 

I'm stuck on a query.  Basically, I would like to return the FIRST row for each item selected that match the criteria specified.

 

For example, I have 73 names, and I would like to return the first row for each name from a table that match my criteria...

 

here's the code I've got so far...

 

SELECT TOP 1 d.DEVICE_NAME, lpd.INTERVAL_DATE
FROM LOAD_PROFILE_DETAILS AS lpd
INNER JOIN DEVICES AS d ON (lpd.DEVICE_ID = d.DEVICE_ID)
WHERE d.DEVICE_ID IN (
SELECT DEVICE_ID FROM DEVICES
WHERE DEVICE_NAME LIKE 'KWH%'
AND PROVISION_STATUS = 2
) 
AND  lpd.RAW_LOAD_VALUE > 0

 

I'm not getting any errors, but the query will run for ever.

Any help would be greatly appreciated!

 

Thanks very much in advance!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.