Dhawal Mhatre Dhawal Mhatre - 5 months ago 19
MySQL Question

using of NOT LIKE in MYSQL & getting error of SubQuery

I have used below mysql query for fetching data:

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


I am getting error

1242 - Subquery returns more than 1 row



can you let me know what wrong in this query

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

Use not in in place of not like. Not in is for comparison of column with a set of values. not like is for comparison of column with a single value or pattern. Your subquery in returning more than one rows. not like can't handle that.

Comments