Problem with JOIN
| From: | Håkan Larsson | Date: | Wed, 05 Feb 2003 03:10:42 +0000 |
| Subject: | Problem with JOIN | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-25444@lists.php.net to get a copy of this message | ||
Hi there.
Im making a kind of a messageboard and trying to save some time with the querys but i cant get it to
work properly.
I have two tables, one with some users and one with messages.
Table : users
+----------+----+
| username | id |
+----------+----+
| user1 | 1 |
| user2 | 2 |
| user3 | 3 |
+----------+----+
Table : messages
+--------+---------+----+
| postid | replyid | id |
+--------+---------+----+
| 1 | 2 | 1 |
| 2 | 3 | 2 |
| 1 | 0 | 3 |
+--------+---------+----+
I have managed to create a query that selects row 1,2 but not row 3.
I want mysql to return row 3 but with a NULL value on the reply id (the message dont have a reply
when first posted).
The output that im gettig follows...
+-------+-------+
| post | reply |
+-------+------ +
| user1 | user2 |
| user2 | user3 |
+-------+-------+
The ouput that i would like to have...
+-------+-------+
| post | reply |
+-------+------ +
| user1 | user2 |
| user2 | user3 |
| user1 | NULL |
+-------+-------+
Thanks in advance.
/Håkan