MySQL many to many relation

MySQL

Sorry is this seems a stupid question, but I have a table of server addresses and a second table with a list of hardware devices which use the addresses, it is possible for multiple devices to use the same server address and a device to use multiple server addresses, so there is a many to many mapping between them.
I am a little confused how I can represent the relationship between them in SQL, so far I am using a third table with the primary keys from the address table and device table and perform two joins in the query, but I'm not sure if this is the best way.

Best Answer

You are doing the right way,

In many-to-many relation your must have a third table mapped by the ID of the two other tables. The two Id must be foreign key, and the association of the two is the primary key of your association's table

You can also store in this table the information that are related on the relation.