Jump to content

Multiple INs


Drongo_III

Recommended Posts

SCRATCH THAT! - had a typo... ;D:suicide:

 

 

Hi Guys

I have another SQL question and I hope someone can help.

I'm trying to run a query with two 'IN' statements.  The first IN statement is compiled from a sub-query and the second is hard coded (its from an external list, which is actually much larger than in the example below)

I keep getting an sql error when I run this through PHP MyAdmin but the error isn't giving me much to go on and I'm not even sure if it's valid to run two IN statements in the same query.  Any help on how I might achieve the above would be most welcome!

Oh and postNumber is an integer representing posts but there are some duplicates in the database hence the DISTINCT query

SELECT * FROM `posts` WHERE `postNumber` IN (SELECT DISTINCT(`postNumber`) FROM `post` WHERE `postYear` >2013) OR `postNumber` IN ('10088','9813','7991')

Drongo

Edited by Drongo_III
Link to comment
Share on other sites

Do you have a table named post and other named posts ?

 

I was thinking they were supposed to be the same table as well. But, if that was the case, there would be no need for either of the IN conditions since the first one would be returning ALL of the possible post numbers. Therefore, the second IN condition would be unnecessary since those numbers (if they existed at all) would be returned from the first IN condition. But, even that one would not be needed since it would be selecting all of then anyway.

Link to comment
Share on other sites

But the first IN condition is getting posts with year > 2013, while the 2nd in might have dates pre 2013. Maybe not in reality, but could.

 

Um, yeah. I guess I need to get a refund on my speed reading class.  ::)

 

So, it probably is a type on the table name in one of those instances.

Edited by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.