[英]How to select records from one table where values from all the records in a column of second table match any of the multiple columns of first table?
There is a table (table A) with columns parent1, parent2..., parent7.有一个表(表 A),其中包含列 parent1、parent2...、parent7。 All these columns contain user_id values, showing user_id values of 7 generations.
所有这些列都包含 user_id 值,显示 7 代的 user_id 值。 Now there is another table (table B) which contains a column of some user_id values.
现在有另一个表(表 B),其中包含一些 user_id 值的列。 I want to select all the records from table A which contain any of the user_db values from table B in any of table A's parent columns.
我想要 select 表 A 中的所有记录,其中包含表 A 的任何父列中表 B 中的任何 user_db 值。 How do I do that?
我怎么做?
Table joins is the way to do this.表连接是执行此操作的方法。
SELECT a.*
FROM table_a a
JOIN table_b b ON (
a.parent1=b.user_id
OR a.parent2=b.user_id
OR a.parent3=b.user_id
OR a.parent4=b.user_id
OR a.parent5=b.user_id
OR a.parent6=b.user_id
OR a.parent7=b.user_id
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.