This should work

INSERT INTO target_table  (id, some_data)
SELECT id, some_data
FROM other_table o
WHERE NOT EXISTS (SELECT 1 FROM target_table t1 WHERE o.id = t1.id);

Assuming column ID is the primary key in both tables.

On Feb 1, 10:03 pm, gabjos <[email protected]> wrote:
> I need to insert records that may or may not exist from one table to
> another. What would be the syntax for doing this?
>
> Basically the tables would need to be compared. If the record in table
> 2 does not exist in table 1 then it gets inserted. If the record does
> exist then nothing is inserted. Can someone help me?

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to