Consider I have the following table:
Id | sid | email
___________________________________________________
1 | 10 | john@yahoo.com
2 | 11 | elsa@gmail.com
3 | 10 | johnconnor@gmail.com
4 | 10 | john.smith@gmail.com
5 | 12 | ninjamutant@yahoo.com
I would like to query all rows which have same "sid" by passing known "email" So if I pass the email as "john.smith@gmail.com", it should return rows with id number 1, 3, and 4.
Try this :
select * from yourtable a
inner join (
select sid
from yourtable
where email = "john.smith@gmail.com"
) b on b.sid = a.sid
select T2.*
from my_table T1 join my_table T2
on T1.sid = T2.sid
where T1.email = 'xxx'
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.