我想通过普通的交互程序链接不同的ids。这是有点复杂,但我会尽我最大的努力来描述这个问题。
以下是步骤1的列表。从表A提取id。
Table A
ID Interactor
1 30
2 40select * from table B where id = 1表B
ID Interactors
1 30
1 32
1 33
1 36
1 38
1 39Table A
ID Interactors
1 30
70 32
76 33
Null 36
89 38
75 39
2 45
2 40
2 434.加入这些不同的ids,以便当我选择1时,我应该得到以下结果。
Select * where id = 1
结果
ID Interactors
1 30
70 32
76 33
89 38
75 39我希望使用sql来实现这一点。
发布于 2019-09-03 07:47:50
试试这个:
select B.ID, B.Interactors
from A inner join B
where A.Interactors = B.Interactors
and A.ID = 1发布于 2019-09-03 08:14:29
从步骤3开始,您有table A,在此之前,您有table B。
您可以使用简单的inner join和where条件来获得您想要的结果。
Select Id, Interactors from
( select tableA.id, tableA.Interactors
from tableA
inner join tableB
on tableA.Interactors = tableB.Interactors
and tableA.Id is not null --- this is required since in your output record having NULL id correspond to tableA is not considered
) as db
where db.Id = 1 ---- you can apply any filter over there to get your desired result.https://stackoverflow.com/questions/57766863
复制相似问题