简体   繁体   中英

Many-To-Many Relationship from one Table in MySQL

I have a table with projects in it and each one has a number to identify the project uniquely. I want to make a many-to-many table to link projects together and this will be done by the user through a GUI. This table would have columns project_id_1 and project_id_2. I wonder what the most efficient way to query the table would be if there are many projects randomly linked together I could have something like:

id1 id2
1 2
3 4
5 6
2 6
4 5

In this case all the projects are linked together. But trying to query this seems impossible without looking through the whole table.

Does anyone have an idea how this could be done better?

Thanks

So in the end I didn't find any MySQL black magic. I just used java and multiple queries. It would have been nice to find a more elegant solution though. I can't be the only one faced with such a case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM