2016-06-18 70 views
0

的得到错误使用不喜欢的我都用下面的MySQL查询获取数据:在MYSQL和子查询

select * 
from tableName 
where tableName.field_type='22' 
    and tableName.field_id NOT LIKE(select aField_id 
    from TableName 02 where status !='Active') 

我收到错误

1242 - 子查询返回多个1行

你可以让我知道自己做错了什么在此查询

回答

2
select * from tableName 
     where tableName.field_type='22' 
     and 
     tableName.field_id 
     NOT IN(select aField_id from TableName where status !='Active') 

使用not in代替not likeNot in用于列与一组值的比较。 not like用于将列与单个值或模式进行比较。您的子查询返回多行。 not like无法处理。

+0

hello akshey, 感谢您的建议,我已经尝试使用NOT IN ...但它返回0行 –

+0

正是你想要实现的查询? –

+0

谢谢akshey,我已经得到了结果.. –

1

像只有一个输入的交易。所以你应该使用IN代替LIKE。