MySQL Forums
Forum List  »  Newbie

Nested Select using Like
Posted by: Peter Dennis
Date: January 10, 2008 04:57PM

Hi All,

I am trying to use the results of a nested select statement in the 'parent' statement using 'LIKE' as per:

SELECT * FROM t1 WHERE c1 LIKE (SELECT c7 FROM t2 WHERE ID = 987);

Does anyone know if this is possible? I am getting empty sets when I experiment with the placement of the % signs. For example:

SELECT * FROM t1 WHERE c1 LIKE "%(SELECT c7 FROM t2 WHERE ID = 987)%";
Empty set (0.01 sec)

Also I have tried to assign the result of the nested select to a variable like:
SELECT @v := c7 FROM t2 WHERE ID = 987;

But again then have no idea how to put this variable "@v" into a statement using LIKE.

Have tried:
SELECT * FROM t1 WHERE c1 LIKE '%@v%';
Empty set (0.00 sec)

Thanks for any help.

Peter.

Options: ReplyQuote


Subject
Written By
Posted
Nested Select using Like
January 10, 2008 04:57PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.