views:

22

answers:

1

I need some mysql code that uses a select output in LIKE statement in WHERE.

I mean something like this:

    SELECT id FROM (SELECT id,parent_id FROM units WHERE ptitle 
like '%(SELECT ptitle FROM units WHERE id='".$id."')%')

Thanks for your help.

+2  A: 

you need to use concat

SELECT id FROM (

SELECT id,parent_id FROM units WHERE ptitle

like concat('%',(SELECT ptitle FROM units WHERE id='".$id."'), '%')

) sub_table
Haim Evgi
thanks Haim,i used your code and it got me an error.but it worked well when i change the positon of concat and put it inside the inner select,in this form: LIKE (SELECT CONCAT('%',ptitle,'%') FROM units WHERE id=...)
hd
i fixed it need "()" Brackets surround the select, thanks
Haim Evgi