Please help me to write a sql query with the conditions as 'NOT LIKE IN'
Select * from Table1 where EmpPU NOT Like IN ('%CSE%', '%ECE%', '%EEE%')
Getting error.
SQL not like statement syntax will be like below. SELECT column FROM table_name WHERE column NOT LIKE pattern; UPDATE table_name SET column=value WHERE column NOT LIKE pattern; DELETE FROM table_name WHERE column NOT LIKE pattern; As an example, let's say we want the list of customer names that don't start with 'A'.
Here is the answer – Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result.
Both are valid, but '<>' is the SQL-92 standard.
You cannot combine like and in. The statement below would do the job though:
Select * from Table1 where EmpPU NOT Like '%CSE%' AND EmpPU NOT Like '%ECE%' AND EmpPU NOT Like '%EEE%'
That's because you're mixing two syntax together.
If you always have exactly those three values, you can just AND the results of three LIKE expressions.
SELECT * FROM Table1 WHERE EmpPU NOT LIKE '%CSE%' AND EmpPU NOT LIKE '%ECE%' AND EmpPU NOT LIKE '%EEE%'
If you need to do it for "any number" of values, you can put the values into a table and do a join.
WITH myData AS ( SELECT '%CSE%' AS match UNION ALL SELECT '%ECE%' AS match UNION ALL SELECT '%EEE%' AS match ) SELECT * FROM Table1 LEFT JOIN myData ON Table1.EmpPU LIKE myData.match WHERE myData.match IS NULL
OR...
WITH myData AS ( SELECT '%CSE%' AS match UNION ALL SELECT '%ECE%' AS match UNION ALL SELECT '%EEE%' AS match ) SELECT * FROM Table1 WHERE NOT EXISTS (SELECT * FROM myData WHERE Table1.EmpPU LIKE match)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With