gudmunson Posted June 7, 2006 Share Posted June 7, 2006 Hey guys,I am trying to write a sub-query to select a subset of data from my database but it is not working. Can somebody take a quick look to see if there is something simple I'm missing? I have tried the subquery by itself and it works, as does the outside query with one value: IN(2384)...so something is wrong. Is this not supported by mysql?[code]SELECT *FROM Schools_equiv_requestWHERE reg_idIN ( SELECT sr.id FROM Students_registration sr LEFT JOIN Programs_terms pt ON pt.id = sr.term_id LEFT JOIN Programs p ON p.id = pt.program_id WHERE p.school_id =88)[/code]Here's what phpmyadmin tells me: MySQL said: Documentation#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select sr . id from Students_registration sr LEFT JOIN Progra Any help would be appreciated, I've been working on this for longer than I'd like to admit [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11446-mysql-sub-query-question/ Share on other sites More sharing options...
fenway Posted June 9, 2006 Share Posted June 9, 2006 Well, you already eliminated the obvious ones (no subquery support, error in the subquery itself), so I'm not really sure. It looks correct syntactically, but obviously, MySQL doesn't agree. What version are you running? And could you post the CREATE TABLE output for all tables involved? I'll take a closer look. Quote Link to comment https://forums.phpfreaks.com/topic/11446-mysql-sub-query-question/#findComment-43544 Share on other sites More sharing options...
gudmunson Posted June 9, 2006 Author Share Posted June 9, 2006 [!--quoteo(post=381755:date=Jun 8 2006, 10:59 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jun 8 2006, 10:59 PM) [snapback]381755[/snapback][/div][div class=\'quotemain\'][!--quotec--]Well, you already eliminated the obvious ones (no subquery support, error in the subquery itself), so I'm not really sure. It looks correct syntactically, but obviously, MySQL doesn't agree. What version are you running? And could you post the CREATE TABLE output for all tables involved? I'll take a closer look.[/quote]I did a bit more research and I'm running mysql 4.0.1, and subqueries weren't supported until version 4.1, so that is my answer! I ended up making a join statement that did away with the subquery altogether. Thanks for the comment though. Quote Link to comment https://forums.phpfreaks.com/topic/11446-mysql-sub-query-question/#findComment-43654 Share on other sites More sharing options...
fenway Posted June 9, 2006 Share Posted June 9, 2006 [!--quoteo(post=381868:date=Jun 9 2006, 11:02 AM:name=gudmunson)--][div class=\'quotetop\']QUOTE(gudmunson @ Jun 9 2006, 11:02 AM) [snapback]381868[/snapback][/div][div class=\'quotemain\'][!--quotec--]I did a bit more research and I'm running mysql 4.0.1, and subqueries weren't supported until version 4.1, so that is my answer! I ended up making a join statement that did away with the subquery altogether. Thanks for the comment though.[/quote]Glad you got it working -- when I first read your post, I got the impression that you _had_ testing subqueries. Whatever -- JOINs are better anyway. Quote Link to comment https://forums.phpfreaks.com/topic/11446-mysql-sub-query-question/#findComment-43735 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.