Jump to content

Recommended Posts

First, I don't need to search a set for a single value. I actually need to do the opposite.

 

I'm filtering my query for a single field that has a single numerical value. This field references another table by it's primary key.

 

table1:
field = value -- references table2.id

table2:
id
data

 

basically, I want results when table1.field is not equal to certain values. Let's say for the ids 1-5, I only want results if the value is NOT 2 or 3.

 

How would I do that without a bunch of where clauses (if possible)?

 

This is how I'm doing it right now:

SELECT
`table1`.*
FROM
`table1`, `table2`
WHERE
`table2`.`id` != '2'
OR
`table2`.`id` != '3'

 

and that works fine... unless I want to filter out like 50 values. Yes, I could do a loop, but I was hoping there was a simpler way.

That'll definitely work for comparison to sequential numerical values, thank you.

 

I'm trying to wrap my head around IN...

 

Am I correct in understanding that the IN operator will return the requested field only if it's value is found in the series of values given?

 

such as this:

SELECT `myField` IN (0, 1, 4, 5)

 

Where if myField is 1, then it will return it, but if myField is 3, it wont? Or am I completely misunderstanding this?

Of course, that's horrible for index usage.

 

It sounds like it's work great for what I need, though I am using it to compare foreign keys. Would this be ill-advised of me to do?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.