[Question] Join Meshes same material

Hello to everyone !

Andybody have got some ideas how can I Join all meshes to one, which has got same material ?

I don’t want to do this by hand because this model has got around 7000 meshes. (This half are same materials)

Example what I mean :

If I have 500 mesh and 200 mesh has got the same material , how can I join them to one automatically ?

I think i need to do something in pythonconsole or I don’t know.

If you just join with Ctrl+J what is the problems. Please be specific with examples