Re: subquery fails, i don't think an outer join will work
> You keep getting "all sorts of error." If you told us what those
> error messages said we might be able to you.
Sorry-
Here are some specifics:
the tables:
CREATE TABLE `students` (
`studentid` INT NOT NULL AUTO_INCREMENT ,
`name` TEXT NOT NULL ,
PRIMARY KEY ( `studentid` )
) TYPE = MYISAM ;
CREATE TABLE `preferences` (
`preferenceid` INT NOT NULL AUTO_INCREMENT ,
`studentid` INT NOT NULL ,
`foodid` INT NOT NULL ,
PRIMARY KEY ( `preferenceid` )
) TYPE = MYISAM ;
CREATE TABLE `food` (
`foodid` INT NOT NULL AUTO_INCREMENT ,
`description` TEXT NOT NULL ,
PRIMARY KEY ( `foodid` )
) TYPE = MYISAM ;
and then the query:
SELECT F.description, count( * )
FROM students S, preferences P, food F
WHERE S.studentID
IN (
SELECT S.studentid
FROM students S, preferences P, food F
WHERE S.studentID = P.studentID
AND P.foodID = F.FoodID
AND F.description LIKE '%blueberries%'
)
AND S.studentID = P.studentID
AND P.foodID = F.foodID
GROUP BY F.foodID
and the result:
MySQL said:
#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 S . studentid from students S , Preferences P , Food F
the subquery by itself works fine, and if i substitute the subquery
with a set of scalars, it also works fine.
and just to make sure my version supports subqueries, here's what
php_info says:
mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 5.0.18
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_INCLUDE -I/usr/local/mysql/include
MYSQL_LIBS -L/usr/local/mysql/lib -lmysqlclient
thanks for taking a look at this, i appreciate it.
Dino
|