Re: Join on single table
| From: | Martin Norland | Date: | Fri, 11 Feb 2005 14:42:36 +0000 |
| Subject: | Re: Join on single table | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-38554@lists.php.net to get a copy of this message | ||
Matthew Weier O'Phinney wrote:
I have a table which contains the following:
id (primary key, auto incrementing)
app_id (integer, foreign key)
resource_id (integer, foreign key)
word
score
(This is a search index.) I want to find all resource_ids from one app_id
that match resource_ids in another app_id by word.
Is this at or near what you're looking for? I don't see any need for killing yourself making the temporary tables/etc. - but maybe I'm missing something. (obviously replace both 'tablename's with your tables name)
SELECT b.app_id, b.resource_id, b.word, b.score FROM tablename AS a, tablename AS b WHERE a.app_id != b.app_id AND a.word = b.word;
Cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International
Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.