简体   繁体   中英

Retrieving data from same table where multiple columns match in multiple rows

I have a table with data where in a situation one rows' id becomes another rows reference id. The table is as below.

在此输入图像描述

I tried to retrieve data as below,

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

but it returns empty table.

Try a self join like :

select * from table1 t1
inner join table1 t2 on t1.id = t2.reference_id

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