从多个列匹配多个行的同一个表中检索数据

问题描述 投票:1回答:1

我有一个数据表,在某种情况下,一行的id成为另一行的引用ID。表格如下。

enter image description here

我试图检索如下数据,

select * from table1 t where t.id = t.reference_id

但它返回空表。

mysql sql select where
1个回答
3
投票

尝试自我加入,如:

select * from table1 t1
inner join table1 t2 on t1.id = t2.reference_id
© www.soinside.com 2019 - 2024. All rights reserved.