grippat Posted November 20, 2007 Share Posted November 20, 2007 I have two tables: Votes and Addresses. Votes contains just "fname" and "lname" fields. Addresses contains "fname", "lname", "address", etc. How can I use just MySQL to insert the data from Addresses into a 3rd table AddressesWithVotes that have matching fname and lname in the Votes table? Link to comment Share on other sites More sharing options...
Reg Edit Posted November 20, 2007 Share Posted November 20, 2007 I have two tables: Votes and Addresses. Votes contains just "fname" and "lname" fields. Addresses contains "fname", "lname", "address", etc. How can I use just MySQL to insert the data from Addresses into a 3rd table AddressesWithVotes that have matching fname and lname in the Votes table?This works in MS SQL, and I assume MySQL too:insert into addresseswithvotes (fname, lname, address)select a.fname, a.lname, a.address from votes vinner join addresses a on a.fname = v.fname and a.lname = v.lname Normally you would have a Person record, and have PersonID rather than fname+lname on the other tables. In that case you would just use PersonID in the join. But anyway, that's the logic. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.