Jump to content

[SOLVED] inserting based on results of a subquery select


spiritssight

Recommended Posts

Hello there,

 

I have the following code:

 

INSERT INTO block (fin, who_blocked) VALUES (irs_rawdata.EIN, 'S-123456789')
WHERE NOT EXISTS
(
SELECT * FROM irs_rawdata
  PNO LIKE '%blind%' OR
  PNO LIKE '%deaf%' OR
  NTEE_Code LIKE '%P87%'
);

 

I have done it with using * in the select and also with EIN as this is the only field need to be inserted into the block table,

 

what am I doing wrong as its saying that there is a error near the WHERE NOT EXISTS clause?

 

Thanks for any help!

 

Sincerely,

Christopher

You can't have a "where" condition after "values" like that in the "insert". You can specify a "select" to retrieve values from another table to be used to "insert" (and for that you place the "select" right after "values").

 

Look at the Insert syntax in the manual:

http://dev.mysql.com/doc/refman/5.0/en/insert.html

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.