Drongo_III Posted December 30, 2014 Share Posted December 30, 2014 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 Link to comment https://forums.phpfreaks.com/topic/293526-multiple-ins/ 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. Link to comment https://forums.phpfreaks.com/topic/293526-multiple-ins/#findComment-1501176 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 ? Link to comment https://forums.phpfreaks.com/topic/293526-multiple-ins/#findComment-1501178 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. Link to comment https://forums.phpfreaks.com/topic/293526-multiple-ins/#findComment-1501181 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. Link to comment https://forums.phpfreaks.com/topic/293526-multiple-ins/#findComment-1501184 Share on other sites More sharing options...
Psycho 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. 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. Link to comment https://forums.phpfreaks.com/topic/293526-multiple-ins/#findComment-1501185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.