Tricky Query
Posted: Thu May 27, 2004 6:12 am
OK, I have two tables, one for posts, the other for replies.
I would like for the query to find distinct posts and replies where tablename.username = '$username'.
This is my current code:
The only rows that return are posts that the $username has posted, and was replied to by someone. I know this is because of this row:
But I need to know how to code it so it will return posts without replies. I'm having a lot of trouble with this.
I would like for the query to find distinct posts and replies where tablename.username = '$username'.
This is my current code:
Code: Select all
SELECT DISTINCT
canterbury_posts_out.post_id, canterbury_posts_out.username,
canterbury_posts_out.category, canterbury_posts_out.subject,
canterbury_posts_out.reply_time
FROM canterbury_posts_out, canterbury_replies_out
WHERE canterbury_posts_out.post_id = canterbury_replies_out.post_id
AND canterbury_posts_out.username = '$username'
OR canterbury_replies_out.username = '$username'
AND canterbury_posts_out.post_id = canterbury_replies_out.post_id
ORDER BY canterbury_posts_out.reply_time DESCCode: Select all
AND canterbury_posts_out.post_id = canterbury_replies_out.post_id