List:General Discussion« Previous MessageNext Message »
From:Baron Schwartz Date:September 24 2007 2:00pm
Subject:Re: bookmarks and keywords
View as plain text  
Hi Kevin,

Kevin Waterson wrote:
> I have a table of bookmarks that have keyword searching.
> Fields
> 
> +-------------+----------------------+--------------------------+------------------+
> | bookmark_id | bookmark_title       | bookmark_url             | bookmark_keyword |
> +-------------+----------------------+--------------------------+------------------+
> |           1 | number one           | http://www.phpro.org     | php              |
> |           2 | number 2             | http://www.freshmeat.net | software         |
> |           3 | three here           | http://www.php.net       | php              |
> |           4 | and four             | http://www.redhat.com    | linux            |
> |           5 | the fifth            | http://www.ez.no         | php              |
> |           6 | this will do         | http://www.google.com    | search           |
> |           7 | something about fish | http://www.youtube.com   | linux            |
> |           8 | finally              | http://www.redhat.com    | php              |
> +-------------+----------------------+--------------------------+------------------+
> 
> I wish to select all bookmark_title and bookmark_url that have the same keywords as
> the bookmark_url 'http://www.redhat.com. I do this..
> mysql> SELECT child.bookmark_id, child.bookmark_title, child.bookmark_url FROM
> bookmarks AS child join bookmarks AS parent ON parent.bookmark_keyword =
> child.bookmark_keyword WHERE child.bookmark_url='http://www.redhat.com' GROUP BY
> child.bookmark_keyword;
> 

That query is right.

> But this returns..
> +-------------+----------------+-----------------------+
> | bookmark_id | bookmark_title | bookmark_url          |
> +-------------+----------------+-----------------------+
> |           4 | and four       | http://www.redhat.com |
> |           8 | finally        | http://www.redhat.com |
> +-------------+----------------+-----------------------+

But, the JOIN table from which those columns come actually has the 
columns you want from the parent table as well.  It's just that you're 
selecting the child columns.

Baron
Thread
bookmarks and keywordsKevin Waterson24 Sep
  • Re: bookmarks and keywordsBaron Schwartz24 Sep
    • Re: bookmarks and keywordsSebastian Mendel24 Sep
    • Re: bookmarks and keywordsKevin Waterson25 Sep
      • Re: bookmarks and keywordsBaron Schwartz25 Sep
        • Re: bookmarks and keywordsSebastian Mendel25 Sep
        • Re: bookmarks and keywordsSebastian Mendel25 Sep
  • Re: bookmarks and keywordsSebastian Mendel24 Sep
    • Re: bookmarks and keywordsBaron Schwartz24 Sep
      • Re: bookmarks and keywordsSebastian Mendel24 Sep