[EMAIL PROTECTED] wrote:
Well, Gordon, looks like you missed the thread. ;-)
Maybe, but his solution is actually pretty close to what the OP wanted
Instead of
INSERT INTO Table1 (...) VALUES ('val1', 'val2', 'val3', ...) <something>
you do
INSERT INTO Table1 (...)
SELECT 'val1', 'val2', 'val3', ...
FROM Table2 WHERE Table2.keycol = 'valtocheck'
Example:
[...CSIMain/csi] 27. mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.14-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use test
Database changed
mysql> create table table1(v1 varchar(20), v2 varchar(20));
Query OK, 0 rows affected (0.18 sec)
mysql> create table table2(k1 varchar(20) primary key, v1 varchar(20));
Query OK, 0 rows affected (0.08 sec)
mysql> insert into table2 values('1', 'v1');
Query OK, 1 row affected (0.04 sec)
mysql> insert into table2 values('2', 'v2');
Query OK, 1 row affected (0.04 sec)
NOW, you want to insert some set of values only if some value (one of
the ones being inserted, or something else in this example) is in table2:
mysql> insert into table1 select 's1', 's2' from table2 where k1 = '0';
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into table1 select 's1', 's2' from table2 where k1 = '1';
Query OK, 1 row affected (0.04 sec)
Records: 1 Duplicates: 0 Warnings: 0
Voila!
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]