MySQL Forums
Forum List  »  General

SQL Question
Posted by: Rob de Jong
Date: May 10, 2005 05:42AM

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

Options: ReplyQuote


Subject
Written By
Posted
SQL Question
May 10, 2005 05:42AM
May 10, 2005 06:03AM
May 10, 2005 07:14AM
May 10, 2005 07:51AM
May 10, 2005 10:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.