First to say I’m using mySQL and my only way of accessing database is over phpMyAdmin since this is for a website.
First I have a table of users like this (table1):
user_id | name
--------------
1 | Mike
2 | Johny
3 | Bob
and another table about their season results (table2):
user_id | season | result
-------------------------
1 | 2009 | 10
1 | 2010 | 8
1 | 2011 | 5
2 | 2009 | 7
2 | 2010 | 3
3 | 2009 | 1
And now I want out the user’s name and his last season’s result, so something like this:
user_id | name | season | result
--------------------------------
1 | Mike | 2011 | 5
2 | Johny| 2010 | 3
3 | Bob | 2009 | 1
The closest I have come to something like this was
SELECT * FROM table1 INNER JOIN table2 ON table1.user_id = table2.user_id GROUP BY id
But I cannot provide that I want the newest season and it just uses a random one.
Anyone has any ideas how to do this?
best regards,
Rok
1 Answer