Jump to content

SQL Insert Question


warrenk

Recommended Posts

I am trying to insert records from tableA into tableB if the records do not exist in tableB.  Here is my sql statement...

 

INSERT INTO str_a1table2( `brands_url` , `brand_name` , `product_url` , `product_name` , `price` )

SELECT `str_a1table1.brands_url` , `str_a1table1.brand_name` , `str_a1table1.product_url` , `str_a1table1.product_name`

FROM str_a1table1

WHERE str_a1table1.brands_url <> str_a1table2.brands_url

AND str_a1table1.brand_name <> str_a1table2.brand_name

AND str_a1table1.product_url <> str_a1table2.product_url

AND str_a1table1.product_name <> str_a1table2.product_name

 

I keep getting syntax errors.  Any help greatly appreciated!

 

Thanks,

Warren

Link to comment
https://forums.phpfreaks.com/topic/38094-sql-insert-question/
Share on other sites

Think of the INSERT INTO and SELECT as two totally different statements. Well at least the select has to work on its own. You can't have table2 in your select because you haven't joined it. Get the Select part working and add the INSERT statement after that.

Link to comment
https://forums.phpfreaks.com/topic/38094-sql-insert-question/#findComment-183431
Share on other sites

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.