problem with a simple query.

# Thread: problem with a simple query.

1. Senior Member
Join Date
Dec 1969
Posts
824

## problem with a simple query.

SELECT *<BR>FROM tblGender<BR>WHERE (Gender &#060;&#062; &#039;F&#039;) OR (Gender &#060;&#062; &#039;M&#039;)<BR><BR>some reason brings back Genders = to F and M aswell.<BR><BR>what am I doing wrong ?<BR><BR><BR>thank you.

2. oli
Senior Member
Join Date
Dec 1969
Posts
3,961

## RE: problem with a simple query.

What gender are looking for ? shouldn&#039;t it be AND not OR ?

3. Senior Member
Join Date
Dec 1969
Posts
7,686

## Jamie, Jamie, Jamie

When are you starting to look at a problem first, and try to solve it yourself? This was, as I&#039;ve said before, you&#039;ll never be able to do this alone...<BR><BR>What do you think you query does?<BR><BR>let&#039;s take my gender as an example (&#039;M&#039;)<BR><BR>the query checks if my gender is not equal to &#039;M&#039; OR not equeal to &#039;F&#039; THAT IS ALWAYS TRUE!<BR><BR>See?

4. Senior Member
Join Date
Dec 1969
Posts
824

## RE: Jamie, Jamie, Jamie

I tried it with AND and I didn&#039;t get any records back, but there should be 100&#039;s<BR><BR>SELECT gender from tblgender where (gender &#060;&#062; &#039;M&#039;) AND (gender &#060;&#062; &#039;F&#039;)<BR>that is correct isn&#039;t it. ?<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Jamie, Jamie, Jamie

That depends.<BR><BR>What do you think it&#039;s going to do?<BR>To me, I think it&#039;s going to select everything in the "tblgender" table, where the gender is NEITHER "M" nor "F". Are you SURE this is what you want it to be? Unless you&#039;re talking neuter/freaks, the only genders ARE "M" and "F".<BR><BR>Or do you have loads of NULLs in there?<BR><BR>Do you want to bring back things from a different table where their genders are neither "M" nor "F"...?!<BR><BR>1) DESCRIBE what you want. If you correctly describe it, it&#039;s quite a simple matter to create the SQL to do it.<BR>2) WRITE a SQL query to attempt #1. If it doesn&#039;t bring back what you want, forget what you wrote in #1 and look at what the query actually DOES. When you find the difference, repeat this step.<BR><BR>Craig.

6. Senior Member
Join Date
Dec 1969
Posts
824

## ok.

yeah, <BR>I just want to show all records that are neither M or F.<BR><BR>I am collecting data, and if the users send a file with the wrong number of fields then data goes into the wrong fields.<BR>the easiest way for me to pick these incorrect files up is to show where the gender is not M or F.

7. Senior Member
Join Date
Dec 1969
Posts
16,931

## Yes, but you haven't DEFINED...

...what you WANT to achieve.<BR><BR>"I just want to show all records that are neither M or F". From WHERE? Where are these records held - in the tblGenders table? Or in a separate table which has a foreign key to the Genders table?!<BR><BR>Describe it (in ENGLISH) as what you want. I.e.<BR>"I want to get all the records from tableX where their gender is not M or F. Genders are held in tableY, where the link between tableX and tableY is tableX.GenderID=tableY.genderID".<BR><BR>Craig.

8. Senior Member
Join Date
Dec 1969
Posts
824

## there is only one table.

sorry,<BR><BR>there is only one table with all the info in, called tblGender.<BR>the table consisits of name, address ,dob , gender<BR><BR>I want to show all the records from that table where gender is not M or F.<BR>

9. Senior Member
Join Date
Dec 1969
Posts
16,931

## Ugh....

...so what ARE they then....?<BR><BR>If they are neither M nor F, what are they?! Are they blank strings? Are they nulls? Come on, I&#039;m trying to lead you to the solution here - you&#039;re very close!<BR><BR>Craig.

10. Senior Member
Join Date
Dec 1969
Posts
824

## anything

They could be anything, thats the problem.<BR>I can;t say where is null ,because they could be a date, a number, a letter, a sentance. anything.<BR>all data is inserted into this table as varchars, I want to collect data no matter how crap it is, then convert it all form this table and remove incorect rows.<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•