SELECT * FROM table_name WHERE column_name like%value%IN(SELECT ...?

时间:2015-07-28 05:52:53

标签: mysql database

我需要一个类似于mysql的查询:

SELECT * FROM table_name 
WHERE column_name like %value% 
   IN (SELECT * FROM table_name WHERE column_name like %second_value%)

我该怎么做?

谢谢!

2 个答案:

答案 0 :(得分:3)

由于我对您的问题的理解是正确的,因此您的查询必须是:

SELECT * FROM table_name 
WHERE column_name like '%value%' and column_name like '%second_value%'

答案 1 :(得分:2)

您无法从嵌套的IN查询中选择多个列。您只能选择一列。

我假设您要从嵌套查询中选择column_name

SELECT * FROM table_name WHERE column_name like '%value%' IN
(SELECT column_name FROM table_name WHERE column_name like '%value%')
//      ^^^^^^^^^^^