tags:

views:

42

answers:

1

Hi, 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.

+6  A: 
SELECT id, name
FROM tblusers
WHERE name LIKE 'j%n' 
AND name NOT LIKE 'John'
Adam Robinson
`AND`: +1. `SELECTR`: -1. Expanding for non-four-letter names: +1. I guess I have to click the up-arrow... :)
Amadan
Great thanks Adam, I can't believe that is one combination i didn't try!
@Amadan: Thanks for the catch; I was typing that rater late at night for me ;)
Adam Robinson