tags:

views:

20

answers:

1

i have a table

table_movie

    mid  muid   actor_name          movie_list(varchar)
    18  act_6   tom hanks       mov_18,mov_19,mov_2,mov_22,mov_23 
    21  act_9   jhonny depp     mov_1,mov_10,mov_20,mov_22,mov_3,mov_9
    28  act_16  bruce willis    mov_18,mov_19,mov_2,mov_22,mov_23 
    29  act_19  jhon trovolta   mov_1,mov_10,mov_20,mov_22,mov_3,mov_9

now i want to dispplay only those actor_name and muidwhich have mov_1( which comes from php) in their movie_list

if i use EXIST then it show error, my query is written below

    `SELECT muid,actor_name FROM table_movie WHERE $movieID EXIST( movie_list)`

i also tried with RLIKE but no results!:(

please tell me how to search a single word from a varchar field

NOTE

my table engine is INNODB so fultext search concept also fails

A: 

What about

SELECT muid,actor_name FROM table_movie WHERE movie_list LIKE '%,$movieID,%'
OR movie_list LIKE '%,$movieID'
OR movie_list LIKE '$movieID,%'
OR movie_list LIKE '$movieID'

?

Edit: I modified the query to take the comments into account. A bit ugly but I guess it would work. Forget about performance. Another problem would be titles with comma in it.

If you can modify the schem you could have a 'movie' table and a 'actor_movie' table.

DrDro
Beat me to it! (15 chars)
awshepard
it will select mov_1 as well as mov_11, mov_12 etc....
diEcho
Although, if `$movieID` were contained in another movie title/id, you might run into problems...depends on your required functionality. If you search for "tar wars" (case-insensitive), should you get back all of the Star Wars movies too?
awshepard