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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.