salted
salted

Reputation: 27

SQL wildcard matching excluding a specific pattern

sorry about the question I am a newbie to sql. i am attempting to create a search query for our database and I was wondering how would you filter certain words from your query for example:

Here is the sample data (the name column): Jean, Jain, Joan, Jorn, Juan, John, Juin

Lets say that we are searching for the names that start with "J" and end with "n" but we don't want to include "John".

SELECT id, name
FROM tblusers
WHERE name LIKE 'j__n'
WHERE name NOT LIKE 'John'

Obviously the above will have an error, so I was wondering how do I correctly write the above.

Thanks in advance.

Upvotes: 1

Views: 3433

Answers (1)

Adam Robinson
Adam Robinson

Reputation: 185643

SELECT id, name
FROM tblusers
WHERE name LIKE 'j%n' 
AND name NOT LIKE 'John'

Upvotes: 7

Related Questions