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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top 2 values for each record

Status
Not open for further replies.

Mary10k

IS-IT--Management
Nov 8, 2001
103
0
0
US
Hello,

I have a table called Labs and a table called EE's. Each EE has many labs in the lab table. I am trying to figure out how I find the top 2 labs (based on date) and return that along with all of the fields in the EE table. Would I use a sub query?
Something like this? SELECT * FROM ee, WHERE ee.id in (select top 2 from labs). This didn't seem to work.
Thank you.
Mary10k
 
you can try something like this (play with it)

select lab,max(datefield),ee.*
from labtb
left join ee
on ee.id=labtb.eeid
group by lab
limit 2

not tested though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top