Jump to content

mysql sub-query question


gudmunson

Recommended Posts

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_request
WHERE reg_id
IN (
  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\" /]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.