Suppose I have
+----------+--------+-----------+
| RACE_ID | NAME | POSITION |
+----------+--------+-----------+
With primary key
+----------+--------+
| RACE_ID | NAME |
+----------+--------+
For a given competitor, I would like to display the name plus the winner of the race. The winner of the race is whoever has POSITION=1 for the given RACE_ID. So something like the following
SELECT NAME, (???) AS WINNER where NAME='Thorpe'
I’m not sure what goes in ???. I’m using Postgres.
assuming the table name is contestant, I’d try something like this below :