KAMAZON
Golden Member
Looking through chapter 3 of "SQL For Beginners" I ran across this simple query.
The query asks to get the name and zip code of all members who do not live on a street which ends with "Street" or "Road", such as "Cherry Road" or "Soto Street". Here is my simple query:
SELECT FirstName + ' ' + LastName AS [Member Name], Zip
FROM MemberDetails
WHERE Street NOT LIKE '% Road' OR Street NOT LIKE '% Street'
The book insists on using AND, and even goes as far as saying "AND" is the obvious choice, but dosen't explain why. I thought the "AND" operator forced it to fit both restrictions. An "OR" operator seems like the only one that would work.
It also has a space after the wildcard (%). Is that space really necissary? Dosen't the wildcard also include spaces as a character anyways? Couldn't I just do do a &Road which would also look for the space and return the exact same result? I would try this out on my home SQL test server but I'm far away from it and my RDP isn't working, so I figured i'd pick your brains for a minute and stop picking my nose. Thanks in advance!
The query asks to get the name and zip code of all members who do not live on a street which ends with "Street" or "Road", such as "Cherry Road" or "Soto Street". Here is my simple query:
SELECT FirstName + ' ' + LastName AS [Member Name], Zip
FROM MemberDetails
WHERE Street NOT LIKE '% Road' OR Street NOT LIKE '% Street'
The book insists on using AND, and even goes as far as saying "AND" is the obvious choice, but dosen't explain why. I thought the "AND" operator forced it to fit both restrictions. An "OR" operator seems like the only one that would work.
It also has a space after the wildcard (%). Is that space really necissary? Dosen't the wildcard also include spaces as a character anyways? Couldn't I just do do a &Road which would also look for the space and return the exact same result? I would try this out on my home SQL test server but I'm far away from it and my RDP isn't working, so I figured i'd pick your brains for a minute and stop picking my nose. Thanks in advance!