Your SQL query is all over the place You have an uncessary join and your group by
is in the wrong place and your left join
syntax is also incorrect. I scrapped it and rewrote it to use min()
properly.
SELECT run, MIN(Time) AS MinTime,
Name AS Timename
From Athletes
group by TimeName
There is no need to run a join
on the same table and if you knew which columns you needed to group by
, there is also no need for a where clause.
Tested and working on sqlfiddle. http://sqlfiddle.com/#!2/13b1a/2
I suggest you read up on what group by
does and how to join
tables properly.
As your table grows, if you aren't using any kind of id or key, you can use a more advanced query that does actually involve a subquery:
select a.run,
a1.name,
a1.Time
from athletes as a
,(select name,
min(time) as Time
from athletes
group by name) as a1
where a.time = a1.Time
and a.name = a1.name
There still isn't a reason to use a join
and the subquery route is the appropriate route to take with your current data set and schema. http://sqlfiddle.com/#!2/23cb4/23