[nycphp-talk] input..select help
Scott Mattocks
crisscott at netzero.com
Mon May 10 13:00:47 EDT 2004
Rahmin Pavlovic wrote:
> insert into table_b(field1,field2) select table_a.field1, table_a.field2 from table_a
>
> Which worked fairly quickly, however it also imported entries from table_a that already exist in table_b.
> So I'm wondering if someone could help me figure out how to just grab the new entries from table_a.
Try something like this:
INSERT INTO table_b (field1, field2)
(SELECT table_a.field1, table_a.field2
FROM table_a
LEFT JOIN table_b
ON (table_a.field1 = table_b.field1
AND
table_a.field2 = table_b.field2)
WHERE table_b.field1 IS NULL
AND table_b.field2 IS NULL)
I would try the select first to make sure that it will get you
everything in table_a that isn't already in table_b. And then if you
like the results from that add the insert part to the begining.
Scott Mattocks
More information about the talk
mailing list
Automatic Email Organization without missing anything!