Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL INSERT/SELECT where not in insert table

Tags:

sql

insert

INSERT INTO     `tableA`
SELECT          `Col1`, 
                `Col2`,
                 NOW() 

FROM            `tableB`

WHERE           tableA.Col1 is not already in tableB.Col1

I can't get the WHERE clause right to ensure that the record copied from tableA only appears in table B once...

like image 777
ed209 Avatar asked Dec 30 '22 03:12

ed209


1 Answers

should read:

where tableA.col1 not in (select col1 from table B)

like image 78
Allan Bowe Avatar answered Jan 01 '23 17:01

Allan Bowe