devnill Posted June 18, 2008 Share Posted June 18, 2008 I am having an issue in PHP where I keep getting errors when i try to run multiple queries using a single mysql_query(). I don't know if this is possible, but at this point I am assuming it is not because single queries run fine. For what I am making, I need to either run 2 simultaneous queries, or use a subquery, but when I do that, the results are totally different. My query should be returning one row, but when the subquery runs, it never returns any rows at all? I am pretty sure this has to do with the order that the queries run, but I have no idea how to fix this. Any ideas? Below is the before and after of my SQL when I use subqueries and 2 separate one: Two seperate queries: SELECT CEILING(RAND()*COUNT(libNum)) INTO @randLib FROM finishedLibs; SELECT finishedLibs.finLib, madlibTemplates.madlib FROM finishedLibs, madlibTemplates WHERE madlibTemplates.mid = finishedLibs.mid AND finishedLibs.libNum=@randLib Single query with a subquery: SELECT finishedLibs.finLib, madlibTemplates.madlib FROM finishedLibs, madlibTemplates WHERE madlibTemplates.mid = finishedLibs.mid AND finishedLibs.libNum=(SELECT CEILING(RAND()*COUNT(libNum)) FROM finishedLibs) Link to comment https://forums.phpfreaks.com/topic/110667-problems-with-subquerys/ Share on other sites More sharing options...
fenway Posted June 18, 2008 Share Posted June 18, 2008 That subquery should be fine... if you replace it with ( SELECT <some libNum that exists> FROM finishedLibs ) does it work? Link to comment https://forums.phpfreaks.com/topic/110667-problems-with-subquerys/#findComment-568144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.