2

I have a listings table that includes an ID and several other fields.

I have a media table that includes an ID and several other fields.

I have a listing_media table that includes its ID, and ID of a listing entry and an ID of a media entry. This gives me many to many relationships between the media and the listings.

                ---------------
----------      |listing_media|
|listing |      ---------------      ----------
----------      | id          |      | media  |
| id     |<-----| listing_id  |      ----------      
| others |      | media_id    |----->| id     |
----------      ---------------      | others |
                                     ----------

My questions:

  • First, is this the best way to allow for a many to many relationship in MySQL?
  • Second, Is there a specific name for the type of table that listing_media represents?

Thanks,

Mike

Intervalia
  • 10,248
  • 2
  • 30
  • 60
  • You should try to avoid many to many relationships. – BlackHatSamurai Apr 20 '20 at 00:23
  • In this case I have many media files that are being saved and those files can be associated with many different listings. If I don't use many-to-many then how would I represent that without data duplication? – Intervalia Apr 20 '20 at 00:25

2 Answers2

4

It is generrally called an associative entity, but also goes by these names (listed alphabetically):

  • association table
  • bridge table
  • cross-reference table
  • crosswalk
  • intermediary table
  • intersection table
  • join table
  • junction table
  • link table
  • linking table
  • many-to-many resolver
  • map table
  • mapping table
  • pairing table
  • pivot table
  • transition table

Non-key data stored in these tables (if any) is usually described as associative data.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
3

listing_media is often referred to as an association table or junction table (and there are no doubt other names as well).

This is the correct way to represent a many-to-many relationship in a relational database.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786