dbTalk Databases Forums  

Subquery problem

comp.databases.mysql comp.databases.mysql


Discuss Subquery problem in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
howa
 
Posts: n/a

Default Subquery problem - 05-13-2008 , 04:49 AM






A simple subquery:


SELECT T2.id FROM T2 WHERE T2.fid IN
(SELECT T2.id FROM T2 WHERE T2.fid = 8);

MySQL returns:

Check the manual that corresponds to your MySQL server version for the
right syntax to use near 'SELECT T2.id FROM T2 WHERE T2.fid...

However, I can run them separately, e.g.

1.

SELECT T2.id FROM T2 WHERE T2.fid IN (1,2,3);

or

SELECT T2.id FROM T2 WHERE T2.fid = 8;


Any idea?

Thanks.

Reply With Quote
  #2  
Old   
Rik Wasmus
 
Posts: n/a

Default Re: Subquery problem - 05-13-2008 , 04:54 AM






On Tue, 13 May 2008 11:49:28 +0200, howa <howachen (AT) gmail (DOT) com> wrote:

Quote:
A simple subquery:


SELECT T2.id FROM T2 WHERE T2.fid IN
(SELECT T2.id FROM T2 WHERE T2.fid = 8);

MySQL returns:

Check the manual that corresponds to your MySQL server version for the
right syntax to use near 'SELECT T2.id FROM T2 WHERE T2.fid...

However, I can run them separately, e.g.

1.

SELECT T2.id FROM T2 WHERE T2.fid IN (1,2,3);

or

SELECT T2.id FROM T2 WHERE T2.fid = 8;


Any idea?
Version?

Avoid subqueries if you can:

SELECT x.id
FROM T2 x
JOIN T2 y
ON y.fid = 8 AND x.fid = y.id
GROUP BY x.id

--
Rik Wasmus
[SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work to
fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SPAM]


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.