It seems to work on my MySQL (4.0.18).

Tell us which version are you using and the error code/message returned.

------ excerpt ------------------------------------------
mysql> create table category
    -> (
    ->   id     tinyint(4)  NOT NULL auto_increment,
    ->   name   varchar(20) NOT NULL,
    ->   parent tinyint(4)  NULL,
    ->   primary key(id)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> insert into category (name, parent) values('cc_1',null);
Query OK, 1 row affected (0.01 sec)

mysql>
mysql> insert into category (name, parent) select 'cc_2a', id from category
where name = 'cc_1';
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from category;
+----+-------+--------+
| id | name  | parent |
+----+-------+--------+
|  1 | cc_1  |   NULL |
|  2 | cc_2a |      1 |
+----+-------+--------+
2 rows in set (0.00 sec)

mysql>
------ excerpt ------------------------------------------


[]s,
Conrado



----- Original Message ----- 
From: "stephen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 16, 2004 2:57 AM
Subject: How could I do this insert/select?


> Hi,
>
> How could I do this insert/select?
>
> create table category
> (
>   id     tinyint(4)  NOT NULL auto_increment,
>   name   varchar(20) NOT NULL,
>   parent tinyint(4)  NULL,
>   primary key(id)
> );
>
> insert into category (name, parent) values('cc_1',null);
> insert into category (name, parent) select 'cc_2a', id from category where
> name = 'cc_1';
>
> MySQL don't like the insert/select.
>
> Thanks
>
>
>
>
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>
>



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

Reply via email to