There are two options
INSERT INTO newtable
SELECT * FROM oldtable
ORDER BY tmstamp_value
ON DUPLICATE KEY UPDATE email=VALUES(email), address=VALUES(address) ... ;
REPLACE INTO newtable
SELECT * FROM oldtable
ORDER BY tmstamp_value;
It mechanically performs a DELETE and an INSERT.
CAVEAT
Notice I applied the ORDER BY against the old table. This should help get the latest data for a give LastName, FirstName.
You should also add a UNIQUE INDEX on the new table as follows:
ALTER TABLE newtable ADD UNIQUE INDEX name_ndx (lastname,firstname);
UPDATE 2013-04-08 17:13 EDT
If you are doing updates, there are two ways to do this:
1. UPDATE JOIN
UPDATE
(SELECT lastname,firstname,phone,email
FROM oldtable ORDER BY lastname,firstname) A
LEFT JOIN newtable B USING (lastname,firstname)
SET B.phone=A.phone,B.email=A.email;
2. UPDATE JOIN with GROUP BY
UPDATE
(
SELECT BB.id,BB.phone,BB.email FROM
(SELECT lastname,firstname,MAX(id) id FROM oldtable GROUP BY lastname,firstname) AA
INNER JOIN oldtable BB USING (lastname,firstname)
) A INNER JOIN newtable B USING (id)
SET B.phone=A.phone,B.email=A.email;
Give it a Try !!!
Both options will take full advantage of the UNIQUE index on name.
It looks like you've used the option to create an Identifying relationship (this is the one with the unbroken line in the toolbox).
An Identifying relationship assumes that the primary key in the referenced table should be part of primary key of the referencing table.
Because Company_id is now part of Department's Primary Key, it must also be part of the foreign key of Employee, hence your problem #1.
What you're probably wanting to do is create a Non-identifying relationship. This can be done by either selecting the dashed line from the toolbox, or unticking "Identifying relationship" in the Foreign Key tab of the Relationship properties.
A Non-identifying relationship is a classic foreign key constraint, and simply ensures that any value in the referencing table exists in the referenced table.
Technically this should resolve your problems, but there are still potential issues with the underlying database design.
For example, there's nothing to stop multiple companies existing with the same name, or multiple departments with the same name, even within the same company.
This could be solved by adding unique key constraints, but another way to tackle the same problem would be to use the Company and Department names as primary keys.
If you were doing this, you'd actually want to use an Identifying relationship, so that the Company name becomes an integral part of the Department.
(You may wish to read up on database theory and database normalisation, as it will help you avoid a lot of traps that you're likely to come up against when building a database)
I'm not suggesting that this is a better database design, simply that this is one where an Identifying relationship is valid / useful.
Best Answer
OK, I have found! It is so easy I am ashamed I didn't find earlier...
Plain old drag and drop.
Just add the column at the bottom, then move it with your mouse to the position you want.