Help with sample query.

M

MN

Hi - I need to run a query to find out in a tableA field gender has some
other value than 1,2,3.
But this will product all records ! It was included 1,2,3,4,5...8,9.
If I using "AND" then it come out just records 4,5,6,7,8,9
Is it weird ? Thank you for any reply .

SELECT *
FROM TableA
WHERE gender<>1 OR gender <> 2 or gender<>3;
 
M

Marshall Barton

MN said:
Hi - I need to run a query to find out in a tableA field gender has some
other value than 1,2,3.
But this will product all records ! It was included 1,2,3,4,5...8,9.
If I using "AND" then it come out just records 4,5,6,7,8,9
Is it weird ? Thank you for any reply .

SELECT *
FROM TableA
WHERE gender<>1 OR gender <> 2 or gender<>3;


And what about the AND didn't you like? Seems like the 4,5
.... are the ones you want to see??

If the problem is that you also have some records where the
gender field is Null, then:

WHERE (gender<>1 AND gender <> 2 AND gender<>3)
OR gender Is Null
 
M

MN

Thank for reply, actual value are: 1,2,3,4,88,99 And I want to see in this
field do they have a different value other than those number?
Regards,

KARL DEWEY said:
SELECT *
FROM TableA
WHERE [Gender] Not Between 1 AND 3;

--
Build a little, test a little.


MN said:
Hi - I need to run a query to find out in a tableA field gender has some
other value than 1,2,3.
But this will product all records ! It was included 1,2,3,4,5...8,9.
If I using "AND" then it come out just records 4,5,6,7,8,9
Is it weird ? Thank you for any reply .

SELECT *
FROM TableA
WHERE gender<>1 OR gender <> 2 or gender<>3;
 
M

MN

I mean I like the AND than but the logical here somthing make me confused?
OK-The user want to print out all of record if the field gender have
diferent value other than 1,2,3,4,77,99 and you was right null is count too.

Thank you.
 
K

KARL DEWEY

SELECT *
FROM TableA
WHERE ([Gender] Not Between 1 AND 3) AND ([Gender] <>88) AND ([Gender] <>99);

--
Build a little, test a little.


MN said:
Thank for reply, actual value are: 1,2,3,4,88,99 And I want to see in this
field do they have a different value other than those number?
Regards,

KARL DEWEY said:
SELECT *
FROM TableA
WHERE [Gender] Not Between 1 AND 3;

--
Build a little, test a little.


MN said:
Hi - I need to run a query to find out in a tableA field gender has some
other value than 1,2,3.
But this will product all records ! It was included 1,2,3,4,5...8,9.
If I using "AND" then it come out just records 4,5,6,7,8,9
Is it weird ? Thank you for any reply .

SELECT *
FROM TableA
WHERE gender<>1 OR gender <> 2 or gender<>3;
 
M

MN

I do like this:

Select *
From tableA
WHERE ((gender Not Between 1 And 4) And (gender<>77) And (gender<>99)) Or
isnull(gender);

Thanks for any reply.

KARL DEWEY said:
SELECT *
FROM TableA
WHERE ([Gender] Not Between 1 AND 3) AND ([Gender] <>88) AND ([Gender] <>99);

--
Build a little, test a little.


MN said:
Thank for reply, actual value are: 1,2,3,4,88,99 And I want to see in this
field do they have a different value other than those number?
Regards,

KARL DEWEY said:
SELECT *
FROM TableA
WHERE [Gender] Not Between 1 AND 3;

--
Build a little, test a little.


:

Hi - I need to run a query to find out in a tableA field gender has some
other value than 1,2,3.
But this will product all records ! It was included 1,2,3,4,5...8,9.
If I using "AND" then it come out just records 4,5,6,7,8,9
Is it weird ? Thank you for any reply .

SELECT *
FROM TableA
WHERE gender<>1 OR gender <> 2 or gender<>3;
 
J

John W. Vinson

Thank for reply, actual value are: 1,2,3,4,88,99 And I want to see in this
field do they have a different value other than those number?

Gender NOT IN(1,2,3,4,88,99)

is a compact way to find records where there is a value in Gender (i.e. not
NULL) but exclude those six specific values.
 
M

Marshall Barton

With more than just 2 or 3 items, I agree with the others
that usin IN is cleaner:

WHERE Not gender In(1, 2, 3, 77, 99) Or gender Is Null
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top