3 ms·
There's actually another issue that I missed before. SELECT * returns all of the columns in the table: you can't compare that to a scalar. Tested on MySQL 5.5
by nbpoole 15y ago
There's actually another issue that I missed before. SELECT * returns all of the columns in the table: you can't compare that to a scalar.
Tested on MySQL 5.5 on OS X:
mysql> use test
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table test (id int(10) unsigned not null auto_increment, name varchar(10), primary key(id));
Query OK, 0 rows affected (0.13 sec)
mysql> insert into test (name) values ("Bob");
Query OK, 1 row affected (0.02 sec)
mysql> select * from test;
+----+------+
| id | name |
+----+------+
| 1 | Bob |
+----+------+
1 row in set (0.00 sec)
mysql> select * from test WHERE (select * FROM test) = 1;
ERROR 1241 (21000): Operand should contain 2 column(s)
mysql> select * from test WHERE (select 1 FROM test) = 1;
+----+------+
| id | name |
+----+------+
| 1 | Bob |
+----+------+
1 row in set (0.00 sec)
mysql> insert into test (name) values ("Frank");
Query OK, 1 row affected (0.00 sec)
mysql> select * from test WHERE (select 1 FROM test) = 1;
ERROR 1242 (21000): Subquery returns more than 1 row