Update table2 t2 set nolines = (select count(*) from table1 t1 where t1.id=t2.id and t1.somecode=2)
It won't be too efficient, I haven't tested it and some versions of SQL aren't happy with it.
You could just re-create table2 to get all the counts; create table2 as select id, desc, count(*) nolines from table1 group by id, desc
Note; not sure this is going to work in the way you want, because you may not want to update all the rows in t2.