If the select statement gives you the correct data, then inserting is easy - add the insert statement like shown in red below:INSERT INTO SCCZ ( state_id, county_id, city_id, zipcode_id)SELECT DISTINCT x1.state_id, x2.county_id, x3.city_id, x4.zipcode_idFROM state AS x1 INNER JOIN datazip AS d ON x1.state_name = d.state INNER JOIN county AS x2 ON d.county = x2.county_name INNER JOIN city AS x3 ON d.city = x3.city_name INNER JOIN zipcode AS x4 ON d.zipcode = x4.zipcode_name