SELECT word FROM table WHERE word NOT LIKE '%a%'
AND word NOT LIKE '%b%'
AND word NOT LIKE '%c%';
Answer from laher on Stack OverflowSELECT word FROM table WHERE word NOT LIKE '%a%'
AND word NOT LIKE '%b%'
AND word NOT LIKE '%c%';
If you use Sqlite's REGEXP support ( see the answer at Problem with regexp python and sqlite for how to do that ) , then you can do it easily in one clause:
SELECT word FROM table WHERE word NOT REGEXP '[abc]';
NOT LIKE Alternatives in WHERE clause – SQLServerCentral Forums
How to put several LIKE & NOT LIKE statements in WHERE SQL clause?
SQL LIKE ANd NOT LIKE - SQLTeam.com Forums
NOT LIKE with '%'
Videos
I've been working on a few automated vendor reports and everything is going fairly well except at the final step when everything is being put together I end up with a few invalid results, such as having ID's that aren't numeric, or ID's that are numeric but have a % sign in them and are therefore invalid.
Googling for these answers wasn't exactly easy because of how many other related articles there are so I thought I'd share:
WHERE
ID NOT LIKE '%[%]%'
OR ID NOT LIKE '%[^0-9]%'Happy Sunday.
Use brackets to make it easier to see, and no commas (probably a typo)
WHERE (ColumnName NOT LIKE ‘string’)
AND (ColumnName NOT LIKE ‘string2’)
Guys,
I am doing a SELECT statement and need to combine several LIKE… & NOT LIKE things in my WHERE clause to wash the data.
It will let me do: WHERE ColumnName NOT LIKE ‘string’
But when I try to add several of these it gives me an error.
For ex:
WHERE ColumnName NOT LIKE ‘string’,
AND ColumnName NOT LIKE ‘string2’
What is the proper syntax to combine several LIKE & NOT LIKE parameters in the same WHERE clause of a Microsoft SQL Server SELECT statement?
Thank you!!!
So using MS SQL Server, I am wondering why this works (get cities that start and end with vowel)
SELECT DISTINCT CITY FROM STATION WHERE CITY LIKE '[AEIOU]%[AEIUO]'
but for finding cities that do not start and end with vowel I can't just add a NOT into the above SQL, instead I have to do
SELECT DISTINCT CITY FROM STATION WHERE CITY NOT LIKE '[AEIOU]%' AND CITY NOT LIKE '%[AEIUO]'
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)