If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Other > Getting one of many in Mimer

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-20-09, 09:20
rhedgate rhedgate is offline
Registered User
 
Join Date: Apr 2009
Posts: 3
Getting one of many in Mimer

I have this table i mimer:

ID NumberID Time
1 1 1000
2 1 1000
3 1 900
4 2 950

I want to SELECT the ID with different NumberID and highest Time, but only one per Number ID.

My SELECT is as follows:

SELECT ID FROM Table AS T1
WHERE
(T1.Time= (
SELECT MAX (T2.Time) FROM Table AS T2
WHERE T2.NumberID = T1.NumberID))

this returns ID: 1, 2 and 4.

I want ta have a SELECT which returns 1 or 2 (doesnīt matter which one) and 4.

My problem is that neither FIRST or TOP works in Mimer, does anyone have a work around for that?
Reply With Quote
  #2 (permalink)  
Old 04-20-09, 10:14
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,307
Materialize all three columns, then GROUP BY NumberID and apply either Min() or Max() to ID.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 04-20-09, 10:35
rhedgate rhedgate is offline
Registered User
 
Join Date: Apr 2009
Posts: 3
I donīt understand what you mean. I tried to use GROUP BY but I couldnīt get it to work because it complaines about ID not groupable. Could you give some example code?

I tried

SELECT ID, NumberID FROM Table AS T1
WHERE
(T1.Time= (
SELECT MAX (T2.Time) FROM Table AS T2
WHERE T2.NumberID = T1.NumberID))
GROUP BY NumberID

but this doesnīt work. Error message: Column ID not referenced in GROUP BY clause
Reply With Quote
  #4 (permalink)  
Old 04-20-09, 11:08
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,307
Keep in mind that I don't have a copy of Mimer here to test this, but I'm pretty sure that you can use:
Code:
SELECT Min(ID), NumberID
   FROM Table AS T1
   WHERE (T1.Time= (
      SELECT MAX (T2.Time)
         FROM Table AS T2
         WHERE T2.NumberID = T1.NumberID))
   GROUP BY NumberID
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #5 (permalink)  
Old 04-20-09, 11:50
rhedgate rhedgate is offline
Registered User
 
Join Date: Apr 2009
Posts: 3
Talking

I understand and it works. Thank you for the help.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On