SQL syntax help

Catboxer

[H]ard|Gawd
Joined
Feb 1, 2003
Messages
1,050
We're trying to have our database filter out the user's selected values from the query results. Can you please advise on what is wrong with the SQL syntax?


Results is the name of the table
Classification is the name of a Column on the table
All the ::values:: are values of the classification column


Select * FROM RESULTS WHERE CLASSIFICATION != ::Blue Chip:: AND CLASSIFICATION != ::Tobacco::
AND CLASSIFICATION != ::Automotive::
AND CLASSIFICATION != ::pharmaceutical::
AND CLASSIFICATION != ::Technology::
 
assuming the classification column is a varchar/text field, wouldn't the strings you are comparing need to be in single quotes?
Code:
SELECT * FROM ... WHERE CLASSIFICATION != '::Blue Chips::' AND ...
 
Thanks that was part of the problem...But why does this code work?

SELECT * FROM Results
WHERE CLASSIFICATION = '::Blue Chip::'

But if I include the not statement it does not work:

SELECT * FROM Results
WHERE CLASSIFICATION != '::Blue Chip::'

EDIT: OK, Nevermind. It's working now. Thanks for the help.
 
Catboxer said:
Thanks that was part of the problem...But why does this code work?

SELECT * FROM Results
WHERE CLASSIFICATION = '::Blue Chip::'

But if I include the not statement it does not work:

SELECT * FROM Results
WHERE CLASSIFICATION != '::Blue Chip::'

EDIT: OK, Nevermind. It's working now. Thanks for the help.

Simple - because SQL uses the "NOT" syntax, rather than the "!=" syntax (for the reference of anyone who wants to know what the actual solution is).

For future reference, it's not polite to just post a "fixed it" message without actually posting the solution.
 
i suppose it would depend on the SQL server type but mysql you can use !=, at least on version 4.0.12, i guess it's not considered 'strict' sql
 
Another example....
Code:
Select * FROM RESULTS WHERE CLASSIFICATION NOT IN ('::Blue Chip::', '::Tobacco::', '::Automotive::', '::Pharmaceutical::', '::Technology::')
 
Back
Top