SQL Question
Hi All,
I'm struggling to get the right syntax for something that seems like it should be do-able. I have two tables, table 1 with (id, name) and table 2 with (id, userid, ranking). The id's are the same, primary key table 1 is (id), and primary key table 2 is (id, userid).
Now I want to have a list of all entries in table 1, and - if available for a user - ordered by ranking. The problem is that not all entries in table 1 will have a ranking in table 2, yet I do want those in my result.
Say, table 1 contains
1, aaa
2, bbb
3, ccc
and table 2 contains
1, 999, 10
2, 999, 20
(999 is the userid).
In my query I want as a result all entries in table 1, order by ranking for those available for user with userid=999. So, something like :
aaa, 10
bbb, 20
ccc, NULL
A join on id's however gives
aaa, 10
bbb, 20
so drops the ccc-row
Is this possible in MySQL?
Thanks!
Rob