Re: discussion forum from j. meloni's book
| From: | Anthony Ritter | Date: | Wed, 13 Aug 2003 01:56:38 +0000 |
| Subject: | Re: discussion forum from j. meloni's book | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-159381@lists.php.net to get a copy of this message | ||
Jennifer Goodie" <goodie@apollointeractive.com> writes:
> You didn't switch the aliases around, you just switched the join order.
> This will provide unexpected results. In order to understand it, you
should
> read up on left joins.
> http://www.mysql.com/doc/en/JOIN.html
............................
Thank you. But...
// the query
$verify = "select ft.topic_id, ft.topic_title from forum_posts as fp left
join forum_topics as ft on fp.topic_id = ft.topic_id where fp.post_id =
$_GET[post_id]";
...........................
My question: why - or how can - the columns ft.topic_id and ft.topic_title
come from the table forum_posts?
In the original schema, there is no column called topic_title in the table
called forum_posts.
When I change the following to read:
$verify = "select ft.topic_id, ft.topic_title from forum_topics as ft left
join forum_posts as fp on fp.topic_id = ft.topic_id where fp.post_id =
$_GET[post_id]";
It works fine.
/*Roughly translated: Select the column ft.topic_id along with the column
ft.topic_title from the table called forum_topics which we'll call ft. Then
join the table called forum_topics onto the table called forum_posts and
match the records where topic_id corresponds in both tables along with
post_id corresponds in both tables.*/