Table Association problems include the following three tables: Album table, product table, and image table.
Requirement: the album can be saved to products and images at the same time.
How can we express the relationship between the three elements?
I analyzed the relationship between albums and products, and between albums and images.
Do you want to design two intermediate tables?
Reply to discussion (solution)
You can create another table between the album table and product table, and store the product id album id (separated by commas)
The same is true for pictures and albums.
As mentioned above, the product id album id should be available in each table so that they can be associated with each other.
You can create another table between the album table and product table, and store the product id album id (separated by commas)
The same is true for pictures and albums.
I have also thought about this method. if you want to query products and images in the same album separately, do you want to query them separately?
If you save the product id and image id connected by commas, you do not need to create a table.
The purpose of creating a transition table is to achieve high-speed access. if you connect the target id to a string, you cannot use the index.
If you save the product id and image id connected by commas, you do not need to create a table.
The purpose of creating a transition table is to achieve high-speed access. if you connect the target id to a string, you cannot use the index.
My original intention is to create a third transition table. It's just the relationship between the three. how can we design this transition table.
Topic id product id Image id
Generally, products and images correspond to each other.
Therefore, the table's sparsity is not too large.
Topic id product id Image id
Generally, products and images correspond to each other.
Therefore, the table's sparsity is not too large.
In my system, products and images come from two entities. Separate two tables. This image is not a product image.
Then separate them.
Topic id product id
Topic id Image id
Since there are two entities, why do you need to get them together? Do you want to design two intermediate tables?
Then separate them.
Topic id product id
Topic id Image id
Since there are two entities, why do you need to get them together? Do you want to design two intermediate tables?
Because these two entities can be stored in the album. If the two entities appear in the same album at the same time. How to query
Select * from A left join A_ B on A. id = A_ B .aid left join A_C on A. id = A_C.aid
Select * from A left join A_ B on A. id = A_ B .aid left join A_C on A. id = A_C.aid
Now you are talking about the joint query of the album table and the two intermediate tables A_ B and A_C. However, the intermediate table only stores the primary keys of two tables. if you want to query the specific information, the information of the comparison table and product table. Whether to continue left join graph table or left join Product Table.
That's of course!
But you only need inner join.
That's of course!
But you only need inner join.
Okay. thank you for your help!