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%';
Answer from Paddy on Stack OverflowDigitalOcean
digitalocean.com › community › tutorials › sql-like-sql-not-like
SQL Like - SQL Not Like | DigitalOcean
August 4, 2022 - There are two wildcards that are used with the LIKE operator. %: Percentage is used for representation of single, multiple or no occurrence. _: The underscore is used for representation of a single character. To use SQL LIKE operator, we must be very sure of the usage of the wildcard position as that will define the search pattern.
Top answer 1 of 10
147
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%';
2 of 10
29
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)
How to use LIKE and NOT LIKE together in a SQL Server query - Stack Overflow
@Gordon Linoff, When we use starting % wildcard in like query at that time index for that column will be used or not? If not how to overcome that issue? More on stackoverflow.com
SQL LIKE ANd NOT LIKE - SQLTeam.com Forums
Hi All, I am wondering if someone could help me with an SQL query. I need to return results from a table with words which have 'an' in them; so I am using '%an%' but i don't want the word 'AND' to show up which it is doing. How can I have one but leave out 'and'? Thanks! More on forums.sqlteam.com
What is NOT LIKE operator in SQL?
The syntax for using the NOT LIKE operator in SQL is: SELECT column1, column2, ... FROM table_name WHERE column_name NOT LIKE pattern; The pattern typically includes wildcards such as % or _: More on designgurus.io
Query Operator "Like" does not work like in SQL (wildcard %)
Loading · ×Sorry to interrupt · Refresh More on forums.ivanti.com
Videos
14:55
16-LIKE Operator & Wildcard Characters | NOT LIKE Operator | ESCAPE ...
03:38
MS SQL tutorial covering where clause using LIKE, NOT LIKE, wildcard ...
00:48
NOT LIKE Operator with SELECT Command - SQL Basics Tutorial - Part ...
03:50
Using Like And Not Like with SQL Where Clause - YouTube
07:36
SQL Tutorial - 23: The LIKE Operator and Wildcard Characters - YouTube
W3Schools
w3schools.com › sql › sql_wildcards.asp
SQL Wildcard Characters
Return all customers that starts with the letter 'a': SELECT * FROM Customers WHERE CustomerName LIKE 'a%'; Try it Yourself » · * Not supported in PostgreSQL and MySQL databases.
LearnSQL.com
learnsql.com › blog › like-sql-not-like
What Do the Operators LIKE and NOT LIKE Do? | LearnSQL.com
March 4, 2021 - Notice how the second letter of the name can be anything. Our SQL query is ignoring that letter and looking for the pattern we have specified. Let’s look at another example. This time, we will substitute two characters with two underscore _ wildcard characters. SELECT FirstName, LastName FROM person_info WHERE LastName LIKE 'Wa__';
W3Schools
w3schools.com › sql › sql_like.asp
SQL LIKE Operator
SELECT * FROM Customers WHERE CustomerName LIKE '_r%'; Try it Yourself » · If no wildcard is specified, the phrase has to have an exact match to return a result. ... If you want to use W3Schools services as an educational institution, team ...
Programiz
programiz.com › sql › like-operator
SQL LIKE and NOT LIKE Operators (With Examples)
-- select customers whose -- country ... whose country name starts with U followed by exactly one character. We can also invert the working of the LIKE operator by using the NOT operator with it....
Snowflake Documentation
docs.snowflake.com › en › sql-reference › functions › like
[ NOT ] LIKE | Snowflake Documentation
When either LIKE or NOT LIKE is specified, returns NULL if any argument is NULL. To include single quotes or other special characters in pattern matching, you can use a backslash escape sequence. NULL does not match NULL. In other words, if the subject is NULL and the pattern is NULL, that ...
UniversalClass
universalclass.com › articles › computers › sql › using-the-in-not-and-like-operators-in-sql.htm
Using the IN, NOT, and LIKE Operators in SQL
These statements get complex when ... build complex statements include IN, NOT, and LIKE. LIKE uses wildcards, which are used to query similar values, but IN and NOT return precise record sets based on specific values....
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › language-elements › like-transact-sql
LIKE (Transact-SQL) - SQL Server | Microsoft Learn
A character put in front of a wildcard character to indicate that the wildcard is interpreted as a regular character and not as a wildcard. escape_character is a character expression that has no default and must evaluate to only one character.
Ivanti Community
forums.ivanti.com › s › question › 0D51B00005BxrusSAB › query-operator-like-does-not-work-like-in-sql-wildcard-
Query Operator "Like" does not work like in SQL (wildcard %)
April 21, 2017 - Loading · ×Sorry to interrupt · Refresh