Rob de Jong wrote:
> 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.
> A join on id's however gives
> aaa, 10
> bbb, 20
> so drops the ccc-row
You need a LEFT JOIN:
SELECT
table1.name,
table2.ranking
FROM table1
LEFT JOIN table2 ON table2.id = table1.id
See
http://dev.mysql.com/doc/mysql/en/join.html
--
felix
Please use
BBCode to format your messages in this forum.