0
SELECT *  
FROM TABLE_X  
WHERE 'Value' IN (SELECT * FROM TABLE_Y)  

What expression can I use instead of 'Value' so that the WHERE clause where always return true?

I am trying to do something like:

WHERE (SELECT field FROM TABLE_Y) LIKE '%Value%'
Rami Zebian
  • 539
  • 1
  • 5
  • 23

3 Answers3

1

Found the solution, use EXISTS instead of WHERE IN:

SELECT *  
FROM TABLE_X   
WHERE EXISTS (SELECT field FROM TABLE_Y WHERE field LIKE '%Value%') 
jarlh
  • 42,561
  • 8
  • 45
  • 63
Rami Zebian
  • 539
  • 1
  • 5
  • 23
0

I don't know if I understood it well, it's silly to do the following, but returns all the records in TABLE_X:

SELECT *
FROM TABLE_X 
WHERE 1 IN (SELECT field FROM TABLE_Y) 

NOTE: ...IN (SELECT * ...) crashes because you should choose just one column, that's why I wrote field instead of *

Kamae
  • 541
  • 2
  • 9
  • 19
0

You cannot compare your 'Value' with *, you need a specified field from TABLE_Y, for example:

SELECT * 
FROM TABLE_X
WHERE (SELECT Field FROM TABLE_Y WHERE Field LIKE '%Value%' LIMIT 1) IS NOT NULL
Battle Mage
  • 369
  • 2
  • 5