Re: Join or Cross Product

From: chris.danx <spamoff.danx_at_ntlworld.com>
Date: Sun, 25 Aug 2002 18:38:38 +0100
Message-ID: <kD8a9.3086$JH6.17487_at_newsfep3-gui.server.ntli.net>


John Gilson wrote:

> Hope this helps.

It does, cheers.

How do you use a nested query in SQL? (the schema is the same as in my first post).

   SELECT P.Number

	 FROM Project AS P
	 WHERE P.Name = 'ProductX'
     		 AND P.ControllingDept = 5

I want to use that to get the employees who work in that department, but can't seem to get it right.

I tried

SELECT *
FROM WorksOn as W
WHERE W.Proj IN

   (SELECT P.Number

	 FROM Project AS P
	 WHERE P.Name = 'ProductX'
     		 AND P.ControllingDept = 5);

but that gives this rather unhelpful error in MySQL...

ERROR 1064: You have an error in your SQL syntax near '(SELECT P.Number

          FROM Project AS P
          WHERE P.Name = 'ProductX'
                  AND P' at line 3



Chris

-- 
for personal replies change 'spamoff' to 'chris'
Received on Sun Aug 25 2002 - 19:38:38 CEST

Original text of this message