[英]Returns all rows which have same column value based on other column value
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.我想通过传递已知的“电子邮件”来查询具有相同“sid”的所有行所以如果我将电子邮件作为“john.smith@gmail.com”传递,它应该返回 ID 号为 1、3 和 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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.