Mysql advanced SELECT, or multiple SELECTS? Movies keywords

Posted by Supyxy on Stack Overflow See other posts from Stack Overflow or by Supyxy
Published on 2010-06-16T18:53:05Z Indexed on 2010/06/16 19:32 UTC
Read the original article Hit count: 237

Filed under:
|
|
|
|

I have a mysql database with movies as follows:

MOVIES(id,title)

KEYWORDS_TABLE(id,key_id) [id is referenced to movies.id, key_id is refernced to keywords.id]

KEYWORDS(id,keyword) //this doesn't matter on my example..

Basically i have movies with their titles and plot keywords for each one, i want to select all movies that have the same keywords with with a given movie id.

I tried something like:

SELECT key_id FROM keywords_table WHERE id=9

doing that in php and storing all the IDs in an array $key_id.. then i build another select that looks like:

SELECT movies.title FROM movies,keywords_table WHERE keywords_table.key_id=$key_id[1] OR keywords_table.key_id=$key_id[2] OR ......... OR keywords_table.key_id=$key_id[n]

This kinda works but it takes too much time as we talk about a database with thousands of thousands of records.

So, any suggestions?? thanks!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about database