Re: Join on single table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux