I think SQL's DISTINCT will get you what you want (I'm assuming the scope of the question is just SQL {so it's OT}, and not DBI usage -- if it is, check tutorials/docs/search for DBI for a plethera of info and post back w/what's causing problems).
INSERT INTO last_visits ( id, domain )
SELECT DISTINCT id, domain FROM heap_in