Mysql – How to retrieve data from a table with two of the columns in the table with the same value

MySQLself-join

UserName, UserID, FollowingUserID
'RachelLim', '1003', '1004'
'YunaKim', '1005', '1007'
'AustinLee', '1007', '1005'
'BenChoi', '1010', '1001'
'RebeccaFang', '1009', '1004'
'AliceAng', '1004', '1003'

Basically, i want to find rows in which userid = followinguserid. How do i do it using select?

Best Answer

You can use SELF JOIN to get result

select t1.* 
from my_table as t1
join my_table as t2 on t1.userid = t2.followinguserid