什么是找出同一个表中一组列中是否存在值的最佳方法

时间:2021-02-13 22:26:38

Say I had a MySQL table which sorts relationships between users (where there is more than 2 columns of users). Whats the best way to check if a user exists in any of a set of columns within the table?

假设我有一个MySQL表,用于对用户之间的关系进行排序(其中有超过2列用户)。什么是检查用户是否存在于表中任何一列中的最佳方法?

Heres a sample table:

下面是样本表:

user_relationships('id', 'team', 'teammember1', 'teammember2' 'teammember3' 'teammember4' 'teammember5' 'teammember6' 'teammember7' 'teammember8' 'teammember9');

Thanks in advance, Ferdia

在此先感谢,Ferdia

1 个解决方案

#1


3  

Where teammmeber1=USER OR teammember2=USER OR teammember3=USER.........

team teamber1 = USER或teammember2 = USER OR teammember3 = USER .........

I wouldn't make the table look like that... But that's your decision

我不会让桌子看起来那样......但这是你的决定

I would make it look like:

我会让它看起来像:

Table - Teams :
id,name,someotherinfo
Table - Team-Members :
team_id, user_id

#1


3  

Where teammmeber1=USER OR teammember2=USER OR teammember3=USER.........

team teamber1 = USER或teammember2 = USER OR teammember3 = USER .........

I wouldn't make the table look like that... But that's your decision

我不会让桌子看起来那样......但这是你的决定

I would make it look like:

我会让它看起来像:

Table - Teams :
id,name,someotherinfo
Table - Team-Members :
team_id, user_id