Drongo_III Posted December 30, 2014 Share Posted December 30, 2014 (edited) SCRATCH THAT! - had a typo... Hi GuysI 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 December 30, 2014 by Drongo_III Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted December 30, 2014 Share Posted December 30, 2014 So what is the error? What does MySQL say? Syntactically, the query is perfectly valid. Quote Link to comment Share on other sites More sharing options...
mikosiko Posted December 30, 2014 Share Posted December 30, 2014 Do you have a table named post and other named posts ? Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 30, 2014 Share Posted December 30, 2014 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. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted December 30, 2014 Share Posted December 30, 2014 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 30, 2014 Share Posted December 30, 2014 (edited) 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 December 30, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.