Updating 1 table from another table.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ron_j_m
Forum Commoner
Posts: 35
Joined: Wed Feb 02, 2005 8:56 pm

Updating 1 table from another table.

Post by ron_j_m »

Heres the situation.
I have 2 tables. Table1 and Table2.
I would like to update Table1 with fields from Table2.
So if Table1 Field1 contained May and June,
and Table2 Field2 contained July and September after updating Table1 I would like Field1 to contain May, June, July and September.

Here is what I have been trying with no luck of course.

Code: Select all

'UPDATE Table1 LEFT JOIN Table2 ON Table1.Field1 = Table2.Field1 SET Table1.Field1=Table2.Field1 WHERE Table1.Field1 IS NULL'
Ive been reading and searching all over but there must be something Im just not getting.
Any Ideas..
Thanks
Ron
ron_j_m
Forum Commoner
Posts: 35
Joined: Wed Feb 02, 2005 8:56 pm

Post by ron_j_m »

Ive found somthing that seems to work.

Code: Select all

insert ignore into table1 select * from table2
Is there a better way to do this?

Thanks
Ron
Post Reply