Jump to content

Archived

This topic is now archived and is closed to further replies.

gudmunson

mysql sub-query question

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\" /]

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.