----- Original Message ----- 
From: "kalin mintchev" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 14, 2004 6:05 PM
Subject: syntax question..


> hi everybody..
>
> can somebody please explain what is wrong with this command:
> select t1.data from table1 as t1 where t1.zip=(select * from table2 as t2
> where t2.chain like "%carmike%");
>
I just thought of a possible explanation of the problem *if* you are running
on a version of MySQL that supports subqueries.

1. Your subquery probably should not do a 'select *'. Normally, subqueries
select only one column from their tables, not EVERY column. The only
exception to this that I know about is an EXISTS subquery but this isn't an
exists subquery. In other words, your subquery should be something like
"select t2.zip from table2 as t2 where t2.chain like "%carmike%". Remember,
the WHERE in your outer query is trying to match a zip code in table1 to
whatever you get back from the subquery. If the subquery returns a phone
number or name or an entire row, it is VERY unlikely it will ever match the
zip code from table1.

2. If your subquery returns more than 1 row, you should probably be using
the 'IN' keyword where you have the equals sign. (There are other
possibilities instead of 'IN' but that is by far the most likely thing you
will do.) Remember, the equals operator says that the subquery is returning
exactly one value that has to be searched in the zip code column of table1;
if you return a set of values instead of a single value, you should be using
an operator that expects multiple values, like 'IN'.

Rhino


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to