INSERT INTO calaccess_processed_filings_form497part2item (
    filing_id,
    line_item,
    date_received,
    date_received_thru,
    amount_received,
    transaction_id,
    memo_reference_number,
    recipient_code,
    recipient_committee_id,
    recipient_title,
    recipient_lastname,
    recipient_firstname,
    recipient_name_suffix,
    recipient_city,
    recipient_state,
    recipient_zip,
    candidate_id,
    candidate_title,
    candidate_lastname,
    candidate_firstname,
    candidate_namesuffix,
    candidate_office_code,
    candidate_office_description,
    candidate_jurisdiction_code,
    candidate_jurisdiction_description,
    candidate_district,
    ballot_measure_name,
    ballot_measure_number,
    ballot_measure_jurisdiction,
    support_opposition_code,
    election_date
)
SELECT
    filing.filing_id,
    item_version.line_item,
    item_version.date_received,
    item_version.date_received_thru,
    item_version.amount_received,
    item_version.transaction_id,
    item_version.memo_reference_number,
    item_version.recipient_code,
    item_version.recipient_committee_id,
    item_version.recipient_title,
    item_version.recipient_lastname,
    item_version.recipient_firstname,
    item_version.recipient_name_suffix,
    item_version.recipient_city,
    item_version.recipient_state,
    item_version.recipient_zip,
    item_version.candidate_id,
    item_version.candidate_title,
    item_version.candidate_lastname,
    item_version.candidate_firstname,
    item_version.candidate_namesuffix,
    item_version.candidate_office_code,
    item_version.candidate_office_description,
    item_version.candidate_jurisdiction_code,
    item_version.candidate_jurisdiction_description,
    item_version.candidate_district,
    item_version.ballot_measure_name,
    item_version.ballot_measure_number,
    item_version.ballot_measure_jurisdiction,
    item_version.support_opposition_code,
    item_version.election_date
FROM calaccess_processed_filings_form497filing filing
JOIN calaccess_processed_filings_form497filingversion filing_version
ON filing.filing_id = filing_version.filing_id
AND filing.amendment_count = filing_version.amend_id
JOIN calaccess_processed_filings_form497part2itemversion item_version
ON filing_version.id = item_version.filing_version_id;
