SELECT SUM(first_table.link_id * second_table.factor) as ANSWER
FROM first_table
LEFT JOIN second_table on first_table.link_id = second_table.id
WHERE first_table.counted = 1
SELECT SUM(first_table.link_id * second_table.factor) as ANSWER
FROM first_table
LEFT JOIN second_table on first_table.link_id = second_table.id
WHERE first_table.counted = 1