UPDATE only if COUNT from another table is not zero
Derive a table of counts by id from table2, join the results to table1 and use that join in the UPDATE statement:

UPDATE
  table1 AS t1
  INNER JOIN
    (
      SELECT
        id,
        COUNT(*) AS cnt
      FROM
        table2
      GROUP BY
        id
    ) AS t2 ON t1.id = t2.id
SET
  t1.number = t1.number + t2.cnt
;


The above statement will affect only the table1 rows that have matches in table2.