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!

Getting uniques record but have to fill 2 criterias 1

Status
Not open for further replies.

FinOzRacing

Programmer
Feb 19, 2004
2
FI
Hi all,

I have and F1 results table called laptimes.

i have entered following details from each day
driver,laptime,day,track

where day means the day 1, 2,3,...test day,
track is the track where the testing was done.

Now for example if Kimi Raikkonen drives 3 days test at Valencia (called as track 1) and his best laptimes are
day 1: 70.123 (as seconds in db), day 2: 70.224 but on day 3 he makes laptime of 69.754 seconds

the following
SELECT * FROM laptimes WHERE track=1 GROUP BY driver ORDER BY laptime

When i print out the result from this query it shows to Kimis laptime as 70.123 not the fastest (69.754) without the GROUP BY it get all 3 laptimes in right order, but how i can get only the fastest laptime from every driver?

Idea is i could print out each days results and also combined list with the fastest laptimes from every driver done in different testing days.
 
You can try something like this:
Code:
SELECT driver,MIN(laptime)
  FROM laptimes
 WHERE track=1
 GROUP BY driver
 ORDER BY 2

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Try this .
To get fastest lap times for every driver in each of his test track:
select *
from laptimes a
where laptime = (select min(laptime) from laptimes b
where a.driver = b.driver
and a.tst_track = b.tst_track)

If you want the fastest lap times for every driver regardless of the track.

select *
from laptimes a
where laptime = (select min(laptime) from laptimes b
where a.driver = b.driver)
 
Thanx for you quick replys, got the results working with PHV's code (was the first, i tried it and it worked).
Haven't tested rrrkrishnan code yet, that looks a bit more complicated but i think i understand what it is doing ;)

Thanx again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top